ホーム › Devices.DeviceAndDriverInstallation › SetupDiGetDevicePropertyW
SetupDiGetDevicePropertyW
関数デバイスの指定デバイスプロパティの値を取得する。
シグネチャ
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiGetDevicePropertyW(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
const DEVPROPKEY* PropertyKey,
DEVPROPTYPE* PropertyType,
BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize,
DWORD* RequiredSize, // optional
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| DeviceInfoSet | HDEVINFO | in |
| DeviceInfoData | SP_DEVINFO_DATA* | in |
| PropertyKey | DEVPROPKEY* | in |
| PropertyType | DEVPROPTYPE* | out |
| PropertyBuffer | BYTE* | outoptional |
| PropertyBufferSize | DWORD | in |
| RequiredSize | DWORD* | outoptional |
| Flags | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiGetDevicePropertyW(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
const DEVPROPKEY* PropertyKey,
DEVPROPTYPE* PropertyType,
BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize,
DWORD* RequiredSize, // optional
DWORD Flags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetDevicePropertyW(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData, // SP_DEVINFO_DATA*
IntPtr PropertyKey, // DEVPROPKEY*
out uint PropertyType, // DEVPROPTYPE* out
IntPtr PropertyBuffer, // BYTE* optional, out
uint PropertyBufferSize, // DWORD
IntPtr RequiredSize, // DWORD* optional, out
uint Flags // DWORD
);<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiGetDevicePropertyW(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr, ' SP_DEVINFO_DATA*
PropertyKey As IntPtr, ' DEVPROPKEY*
<Out> ByRef PropertyType As UInteger, ' DEVPROPTYPE* out
PropertyBuffer As IntPtr, ' BYTE* optional, out
PropertyBufferSize As UInteger, ' DWORD
RequiredSize As IntPtr, ' DWORD* optional, out
Flags As UInteger ' DWORD
) As Boolean
End Function' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
' PropertyKey : DEVPROPKEY*
' PropertyType : DEVPROPTYPE* out
' PropertyBuffer : BYTE* optional, out
' PropertyBufferSize : DWORD
' RequiredSize : DWORD* optional, out
' Flags : DWORD
Declare PtrSafe Function SetupDiGetDevicePropertyW Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr, _
ByVal PropertyKey As LongPtr, _
ByRef PropertyType As Long, _
ByVal PropertyBuffer As LongPtr, _
ByVal PropertyBufferSize As Long, _
ByVal RequiredSize 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
SetupDiGetDevicePropertyW = ctypes.windll.setupapi.SetupDiGetDevicePropertyW
SetupDiGetDevicePropertyW.restype = wintypes.BOOL
SetupDiGetDevicePropertyW.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA*
ctypes.c_void_p, # PropertyKey : DEVPROPKEY*
ctypes.c_void_p, # PropertyType : DEVPROPTYPE* out
ctypes.POINTER(ctypes.c_ubyte), # PropertyBuffer : BYTE* optional, out
wintypes.DWORD, # PropertyBufferSize : DWORD
ctypes.POINTER(wintypes.DWORD), # RequiredSize : 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')
SetupDiGetDevicePropertyW = Fiddle::Function.new(
lib['SetupDiGetDevicePropertyW'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA*
Fiddle::TYPE_VOIDP, # PropertyKey : DEVPROPKEY*
Fiddle::TYPE_VOIDP, # PropertyType : DEVPROPTYPE* out
Fiddle::TYPE_VOIDP, # PropertyBuffer : BYTE* optional, out
-Fiddle::TYPE_INT, # PropertyBufferSize : DWORD
Fiddle::TYPE_VOIDP, # RequiredSize : DWORD* optional, out
-Fiddle::TYPE_INT, # Flags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "setupapi")]
extern "system" {
fn SetupDiGetDevicePropertyW(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
PropertyKey: *const DEVPROPKEY, // DEVPROPKEY*
PropertyType: *mut u32, // DEVPROPTYPE* out
PropertyBuffer: *mut u8, // BYTE* optional, out
PropertyBufferSize: u32, // DWORD
RequiredSize: *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 SetupDiGetDevicePropertyW(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, IntPtr PropertyKey, out uint PropertyType, IntPtr PropertyBuffer, uint PropertyBufferSize, IntPtr RequiredSize, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetDevicePropertyW' -Namespace Win32 -PassThru
# $api::SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)#uselib "SETUPAPI.dll"
#func global SetupDiGetDevicePropertyW "SetupDiGetDevicePropertyW" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiGetDevicePropertyW DeviceInfoSet, varptr(DeviceInfoData), varptr(PropertyKey), PropertyType, varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize), Flags ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr"
; PropertyKey : DEVPROPKEY* -> "sptr"
; PropertyType : DEVPROPTYPE* out -> "sptr"
; PropertyBuffer : BYTE* optional, out -> "sptr"
; PropertyBufferSize : DWORD -> "sptr"
; RequiredSize : DWORD* optional, out -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiGetDevicePropertyW "SetupDiGetDevicePropertyW" sptr, var, var, int, var, int, var, int ; res = SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; PropertyKey : DEVPROPKEY* -> "var" ; PropertyType : DEVPROPTYPE* out -> "int" ; PropertyBuffer : BYTE* optional, out -> "var" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiGetDevicePropertyW "SetupDiGetDevicePropertyW" sptr, sptr, sptr, int, sptr, int, sptr, int ; res = SetupDiGetDevicePropertyW(DeviceInfoSet, varptr(DeviceInfoData), varptr(PropertyKey), PropertyType, varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize), Flags) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr" ; PropertyKey : DEVPROPKEY* -> "sptr" ; PropertyType : DEVPROPTYPE* out -> "int" ; PropertyBuffer : BYTE* optional, out -> "sptr" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "sptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiGetDevicePropertyW(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, DEVPROPKEY* PropertyKey, DEVPROPTYPE* PropertyType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD* RequiredSize, DWORD Flags) #uselib "SETUPAPI.dll" #cfunc global SetupDiGetDevicePropertyW "SetupDiGetDevicePropertyW" intptr, var, var, int, var, int, var, int ; res = SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; PropertyKey : DEVPROPKEY* -> "var" ; PropertyType : DEVPROPTYPE* out -> "int" ; PropertyBuffer : BYTE* optional, out -> "var" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; Flags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiGetDevicePropertyW(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, DEVPROPKEY* PropertyKey, DEVPROPTYPE* PropertyType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD* RequiredSize, DWORD Flags) #uselib "SETUPAPI.dll" #cfunc global SetupDiGetDevicePropertyW "SetupDiGetDevicePropertyW" intptr, intptr, intptr, int, intptr, int, intptr, int ; res = SetupDiGetDevicePropertyW(DeviceInfoSet, varptr(DeviceInfoData), varptr(PropertyKey), PropertyType, varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize), Flags) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "intptr" ; PropertyKey : DEVPROPKEY* -> "intptr" ; PropertyType : DEVPROPTYPE* out -> "int" ; PropertyBuffer : BYTE* optional, out -> "intptr" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "intptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiGetDevicePropertyW = setupapi.NewProc("SetupDiGetDevicePropertyW")
)
// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA*), PropertyKey (DEVPROPKEY*), PropertyType (DEVPROPTYPE* out), PropertyBuffer (BYTE* optional, out), PropertyBufferSize (DWORD), RequiredSize (DWORD* optional, out), Flags (DWORD)
r1, _, err := procSetupDiGetDevicePropertyW.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
uintptr(PropertyKey),
uintptr(PropertyType),
uintptr(PropertyBuffer),
uintptr(PropertyBufferSize),
uintptr(RequiredSize),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiGetDevicePropertyW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA*
PropertyKey: Pointer; // DEVPROPKEY*
PropertyType: Pointer; // DEVPROPTYPE* out
PropertyBuffer: Pointer; // BYTE* optional, out
PropertyBufferSize: DWORD; // DWORD
RequiredSize: Pointer; // DWORD* optional, out
Flags: DWORD // DWORD
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiGetDevicePropertyW';result := DllCall("SETUPAPI\SetupDiGetDevicePropertyW"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA*
, "Ptr", PropertyKey ; DEVPROPKEY*
, "Ptr", PropertyType ; DEVPROPTYPE* out
, "Ptr", PropertyBuffer ; BYTE* optional, out
, "UInt", PropertyBufferSize ; DWORD
, "Ptr", RequiredSize ; DWORD* optional, out
, "UInt", Flags ; DWORD
, "Int") ; return: BOOL●SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags) = DLL("SETUPAPI.dll", "bool SetupDiGetDevicePropertyW(int, void*, void*, void*, void*, dword, void*, dword)")
# 呼び出し: SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* -> "void*"
# PropertyKey : DEVPROPKEY* -> "void*"
# PropertyType : DEVPROPTYPE* out -> "void*"
# PropertyBuffer : BYTE* optional, out -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。