Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupDiSetDeviceRegistryPropertyA

SetupDiSetDeviceRegistryPropertyA

関数
指定デバイスのレジストリプロパティ値を設定する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupDiSetDeviceRegistryPropertyA(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,
    SETUP_DI_REGISTRY_PROPERTY Property,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInfoDataSP_DEVINFO_DATA*inout
PropertySETUP_DI_REGISTRY_PROPERTYin
PropertyBufferBYTE*inoptional
PropertyBufferSizeDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupDiSetDeviceRegistryPropertyA(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,
    SETUP_DI_REGISTRY_PROPERTY Property,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiSetDeviceRegistryPropertyA(
    IntPtr DeviceInfoSet,   // HDEVINFO
    IntPtr DeviceInfoData,   // SP_DEVINFO_DATA* in/out
    uint Property,   // SETUP_DI_REGISTRY_PROPERTY
    IntPtr PropertyBuffer,   // BYTE* optional
    uint PropertyBufferSize   // DWORD
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiSetDeviceRegistryPropertyA(
    DeviceInfoSet As IntPtr,   ' HDEVINFO
    DeviceInfoData As IntPtr,   ' SP_DEVINFO_DATA* in/out
    [Property] As UInteger,   ' SETUP_DI_REGISTRY_PROPERTY
    PropertyBuffer As IntPtr,   ' BYTE* optional
    PropertyBufferSize As UInteger   ' DWORD
) As Boolean
End Function
' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA* in/out
' Property : SETUP_DI_REGISTRY_PROPERTY
' PropertyBuffer : BYTE* optional
' PropertyBufferSize : DWORD
Declare PtrSafe Function SetupDiSetDeviceRegistryPropertyA Lib "setupapi" ( _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInfoData As LongPtr, _
    ByVal Property As Long, _
    ByVal PropertyBuffer As LongPtr, _
    ByVal PropertyBufferSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiSetDeviceRegistryPropertyA = ctypes.windll.setupapi.SetupDiSetDeviceRegistryPropertyA
SetupDiSetDeviceRegistryPropertyA.restype = wintypes.BOOL
SetupDiSetDeviceRegistryPropertyA.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA* in/out
    wintypes.DWORD,  # Property : SETUP_DI_REGISTRY_PROPERTY
    ctypes.POINTER(ctypes.c_ubyte),  # PropertyBuffer : BYTE* optional
    wintypes.DWORD,  # PropertyBufferSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiSetDeviceRegistryPropertyA = Fiddle::Function.new(
  lib['SetupDiSetDeviceRegistryPropertyA'],
  [
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
    Fiddle::TYPE_VOIDP,  # DeviceInfoData : SP_DEVINFO_DATA* in/out
    -Fiddle::TYPE_INT,  # Property : SETUP_DI_REGISTRY_PROPERTY
    Fiddle::TYPE_VOIDP,  # PropertyBuffer : BYTE* optional
    -Fiddle::TYPE_INT,  # PropertyBufferSize : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiSetDeviceRegistryPropertyA(
        DeviceInfoSet: isize,  // HDEVINFO
        DeviceInfoData: *mut SP_DEVINFO_DATA,  // SP_DEVINFO_DATA* in/out
        Property: u32,  // SETUP_DI_REGISTRY_PROPERTY
        PropertyBuffer: *const u8,  // BYTE* optional
        PropertyBufferSize: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetupDiSetDeviceRegistryPropertyA(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, uint Property, IntPtr PropertyBuffer, uint PropertyBufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiSetDeviceRegistryPropertyA' -Namespace Win32 -PassThru
# $api::SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
#uselib "SETUPAPI.dll"
#func global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" sptr, sptr, sptr, sptr, sptr
; SetupDiSetDeviceRegistryPropertyA DeviceInfoSet, varptr(DeviceInfoData), Property, varptr(PropertyBuffer), PropertyBufferSize   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "sptr"
; Property : SETUP_DI_REGISTRY_PROPERTY -> "sptr"
; PropertyBuffer : BYTE* optional -> "sptr"
; PropertyBufferSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" sptr, var, int, var, int
; res = SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "var"
; Property : SETUP_DI_REGISTRY_PROPERTY -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiSetDeviceRegistryPropertyA(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SETUP_DI_REGISTRY_PROPERTY Property, BYTE* PropertyBuffer, DWORD PropertyBufferSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" intptr, var, int, var, int
; res = SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
; DeviceInfoSet : HDEVINFO -> "intptr"
; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "var"
; Property : SETUP_DI_REGISTRY_PROPERTY -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiSetDeviceRegistryPropertyA = setupapi.NewProc("SetupDiSetDeviceRegistryPropertyA")
)

// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA* in/out), Property (SETUP_DI_REGISTRY_PROPERTY), PropertyBuffer (BYTE* optional), PropertyBufferSize (DWORD)
r1, _, err := procSetupDiSetDeviceRegistryPropertyA.Call(
	uintptr(DeviceInfoSet),
	uintptr(DeviceInfoData),
	uintptr(Property),
	uintptr(PropertyBuffer),
	uintptr(PropertyBufferSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiSetDeviceRegistryPropertyA(
  DeviceInfoSet: NativeInt;   // HDEVINFO
  DeviceInfoData: Pointer;   // SP_DEVINFO_DATA* in/out
  Property: DWORD;   // SETUP_DI_REGISTRY_PROPERTY
  PropertyBuffer: Pointer;   // BYTE* optional
  PropertyBufferSize: DWORD   // DWORD
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiSetDeviceRegistryPropertyA';
result := DllCall("SETUPAPI\SetupDiSetDeviceRegistryPropertyA"
    , "Ptr", DeviceInfoSet   ; HDEVINFO
    , "Ptr", DeviceInfoData   ; SP_DEVINFO_DATA* in/out
    , "UInt", Property   ; SETUP_DI_REGISTRY_PROPERTY
    , "Ptr", PropertyBuffer   ; BYTE* optional
    , "UInt", PropertyBufferSize   ; DWORD
    , "Int")   ; return: BOOL
●SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize) = DLL("SETUPAPI.dll", "bool SetupDiSetDeviceRegistryPropertyA(int, void*, dword, void*, dword)")
# 呼び出し: SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* in/out -> "void*"
# Property : SETUP_DI_REGISTRY_PROPERTY -> "dword"
# PropertyBuffer : BYTE* optional -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。