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

SetupDiSetDeviceInterfacePropertyW

関数
デバイスインターフェイスの指定プロパティ値を設定する。
DLLSETUPAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// SETUPAPI.dll
#include <windows.h>

BOOL SetupDiSetDeviceInterfacePropertyW(
    HDEVINFO DeviceInfoSet,
    SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
    const DEVPROPKEY* PropertyKey,
    DEVPROPTYPE PropertyType,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    DWORD Flags
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInterfaceDataSP_DEVICE_INTERFACE_DATA*in
PropertyKeyDEVPROPKEY*in
PropertyTypeDEVPROPTYPEin
PropertyBufferBYTE*inoptional
PropertyBufferSizeDWORDin
FlagsDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll
#include <windows.h>

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

SetupDiSetDeviceInterfacePropertyW = ctypes.windll.setupapi.SetupDiSetDeviceInterfacePropertyW
SetupDiSetDeviceInterfacePropertyW.restype = wintypes.BOOL
SetupDiSetDeviceInterfacePropertyW.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
    ctypes.c_void_p,  # PropertyKey : DEVPROPKEY*
    wintypes.DWORD,  # PropertyType : DEVPROPTYPE
    ctypes.POINTER(ctypes.c_ubyte),  # PropertyBuffer : BYTE* optional
    wintypes.DWORD,  # PropertyBufferSize : DWORD
    wintypes.DWORD,  # Flags : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiSetDeviceInterfacePropertyW = setupapi.NewProc("SetupDiSetDeviceInterfacePropertyW")
)

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