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

SetupDiGetDeviceInterfacePropertyKeys

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

シグネチャ

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

BOOL SetupDiGetDeviceInterfacePropertyKeys(
    HDEVINFO DeviceInfoSet,
    SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
    DEVPROPKEY* PropertyKeyArray,   // optional
    DWORD PropertyKeyCount,
    DWORD* RequiredPropertyKeyCount,   // optional
    DWORD Flags
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInterfaceDataSP_DEVICE_INTERFACE_DATA*in
PropertyKeyArrayDEVPROPKEY*outoptional
PropertyKeyCountDWORDin
RequiredPropertyKeyCountDWORD*outoptional
FlagsDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

SetupDiGetDeviceInterfacePropertyKeys = ctypes.windll.setupapi.SetupDiGetDeviceInterfacePropertyKeys
SetupDiGetDeviceInterfacePropertyKeys.restype = wintypes.BOOL
SetupDiGetDeviceInterfacePropertyKeys.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
    ctypes.c_void_p,  # PropertyKeyArray : DEVPROPKEY* optional, out
    wintypes.DWORD,  # PropertyKeyCount : DWORD
    ctypes.POINTER(wintypes.DWORD),  # RequiredPropertyKeyCount : DWORD* optional, out
    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')
SetupDiGetDeviceInterfacePropertyKeys = Fiddle::Function.new(
  lib['SetupDiGetDeviceInterfacePropertyKeys'],
  [
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
    Fiddle::TYPE_VOIDP,  # DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
    Fiddle::TYPE_VOIDP,  # PropertyKeyArray : DEVPROPKEY* optional, out
    -Fiddle::TYPE_INT,  # PropertyKeyCount : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredPropertyKeyCount : DWORD* optional, out
    -Fiddle::TYPE_INT,  # Flags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiGetDeviceInterfacePropertyKeys(
        DeviceInfoSet: isize,  // HDEVINFO
        DeviceInterfaceData: *mut SP_DEVICE_INTERFACE_DATA,  // SP_DEVICE_INTERFACE_DATA*
        PropertyKeyArray: *mut DEVPROPKEY,  // DEVPROPKEY* optional, out
        PropertyKeyCount: u32,  // DWORD
        RequiredPropertyKeyCount: *mut u32,  // DWORD* optional, out
        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 SetupDiGetDeviceInterfacePropertyKeys(IntPtr DeviceInfoSet, IntPtr DeviceInterfaceData, IntPtr PropertyKeyArray, uint PropertyKeyCount, IntPtr RequiredPropertyKeyCount, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetDeviceInterfacePropertyKeys' -Namespace Win32 -PassThru
# $api::SetupDiGetDeviceInterfacePropertyKeys(DeviceInfoSet, DeviceInterfaceData, PropertyKeyArray, PropertyKeyCount, RequiredPropertyKeyCount, Flags)
#uselib "SETUPAPI.dll"
#func global SetupDiGetDeviceInterfacePropertyKeys "SetupDiGetDeviceInterfacePropertyKeys" sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiGetDeviceInterfacePropertyKeys DeviceInfoSet, varptr(DeviceInterfaceData), varptr(PropertyKeyArray), PropertyKeyCount, varptr(RequiredPropertyKeyCount), Flags   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "sptr"
; PropertyKeyArray : DEVPROPKEY* optional, out -> "sptr"
; PropertyKeyCount : DWORD -> "sptr"
; RequiredPropertyKeyCount : DWORD* optional, out -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetDeviceInterfacePropertyKeys "SetupDiGetDeviceInterfacePropertyKeys" sptr, var, var, int, var, int
; res = SetupDiGetDeviceInterfacePropertyKeys(DeviceInfoSet, DeviceInterfaceData, PropertyKeyArray, PropertyKeyCount, RequiredPropertyKeyCount, Flags)
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "var"
; PropertyKeyArray : DEVPROPKEY* optional, out -> "var"
; PropertyKeyCount : DWORD -> "int"
; RequiredPropertyKeyCount : DWORD* optional, out -> "var"
; Flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiGetDeviceInterfacePropertyKeys(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData, DEVPROPKEY* PropertyKeyArray, DWORD PropertyKeyCount, DWORD* RequiredPropertyKeyCount, DWORD Flags)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetDeviceInterfacePropertyKeys "SetupDiGetDeviceInterfacePropertyKeys" intptr, var, var, int, var, int
; res = SetupDiGetDeviceInterfacePropertyKeys(DeviceInfoSet, DeviceInterfaceData, PropertyKeyArray, PropertyKeyCount, RequiredPropertyKeyCount, Flags)
; DeviceInfoSet : HDEVINFO -> "intptr"
; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "var"
; PropertyKeyArray : DEVPROPKEY* optional, out -> "var"
; PropertyKeyCount : DWORD -> "int"
; RequiredPropertyKeyCount : DWORD* optional, out -> "var"
; Flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiGetDeviceInterfacePropertyKeys = setupapi.NewProc("SetupDiGetDeviceInterfacePropertyKeys")
)

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