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

SetupDiGetClassPropertyExW

関数
リモート対応でデバイスクラスの指定プロパティ値を取得する。
DLLSETUPAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL SetupDiGetClassPropertyExW(
    const GUID* ClassGuid,
    const DEVPROPKEY* PropertyKey,
    DEVPROPTYPE* PropertyType,
    BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    DWORD* RequiredSize,   // optional
    DWORD Flags,
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);

パラメーター

名前方向
ClassGuidGUID*in
PropertyKeyDEVPROPKEY*in
PropertyTypeDEVPROPTYPE*out
PropertyBufferBYTE*outoptional
PropertyBufferSizeDWORDin
RequiredSizeDWORD*outoptional
FlagsDWORDin
MachineNameLPCWSTRinoptional
Reservedvoid*optional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiGetClassPropertyExW(
    const GUID* ClassGuid,
    const DEVPROPKEY* PropertyKey,
    DEVPROPTYPE* PropertyType,
    BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    DWORD* RequiredSize,   // optional
    DWORD Flags,
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetClassPropertyExW(
    ref Guid ClassGuid,   // GUID*
    IntPtr PropertyKey,   // DEVPROPKEY*
    out uint PropertyType,   // DEVPROPTYPE* out
    IntPtr PropertyBuffer,   // BYTE* optional, out
    uint PropertyBufferSize,   // DWORD
    IntPtr RequiredSize,   // DWORD* optional, out
    uint Flags,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string MachineName,   // LPCWSTR optional
    IntPtr Reserved   // void* optional
);
<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiGetClassPropertyExW(
    ByRef ClassGuid As Guid,   ' GUID*
    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
    <MarshalAs(UnmanagedType.LPWStr)> MachineName As String,   ' LPCWSTR optional
    Reserved As IntPtr   ' void* optional
) As Boolean
End Function
' ClassGuid : GUID*
' PropertyKey : DEVPROPKEY*
' PropertyType : DEVPROPTYPE* out
' PropertyBuffer : BYTE* optional, out
' PropertyBufferSize : DWORD
' RequiredSize : DWORD* optional, out
' Flags : DWORD
' MachineName : LPCWSTR optional
' Reserved : void* optional
Declare PtrSafe Function SetupDiGetClassPropertyExW Lib "setupapi" ( _
    ByVal ClassGuid 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, _
    ByVal MachineName As LongPtr, _
    ByVal Reserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiGetClassPropertyExW = ctypes.windll.setupapi.SetupDiGetClassPropertyExW
SetupDiGetClassPropertyExW.restype = wintypes.BOOL
SetupDiGetClassPropertyExW.argtypes = [
    ctypes.c_void_p,  # ClassGuid : GUID*
    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
    wintypes.LPCWSTR,  # MachineName : LPCWSTR optional
    ctypes.POINTER(None),  # Reserved : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiGetClassPropertyExW = Fiddle::Function.new(
  lib['SetupDiGetClassPropertyExW'],
  [
    Fiddle::TYPE_VOIDP,  # ClassGuid : GUID*
    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_VOIDP,  # MachineName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # Reserved : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiGetClassPropertyExW(
        ClassGuid: *const GUID,  // GUID*
        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
        MachineName: *const u16,  // LPCWSTR optional
        Reserved: *mut ()  // void* optional
    ) -> 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 SetupDiGetClassPropertyExW(ref Guid ClassGuid, IntPtr PropertyKey, out uint PropertyType, IntPtr PropertyBuffer, uint PropertyBufferSize, IntPtr RequiredSize, uint Flags, [MarshalAs(UnmanagedType.LPWStr)] string MachineName, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetClassPropertyExW' -Namespace Win32 -PassThru
# $api::SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
#uselib "SETUPAPI.dll"
#func global SetupDiGetClassPropertyExW "SetupDiGetClassPropertyExW" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiGetClassPropertyExW varptr(ClassGuid), varptr(PropertyKey), PropertyType, varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize), Flags, MachineName, Reserved   ; 戻り値は stat
; ClassGuid : GUID* -> "sptr"
; PropertyKey : DEVPROPKEY* -> "sptr"
; PropertyType : DEVPROPTYPE* out -> "sptr"
; PropertyBuffer : BYTE* optional, out -> "sptr"
; PropertyBufferSize : DWORD -> "sptr"
; RequiredSize : DWORD* optional, out -> "sptr"
; Flags : DWORD -> "sptr"
; MachineName : LPCWSTR optional -> "sptr"
; Reserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetClassPropertyExW "SetupDiGetClassPropertyExW" var, var, int, var, int, var, int, wstr, sptr
; res = SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
; ClassGuid : GUID* -> "var"
; PropertyKey : DEVPROPKEY* -> "var"
; PropertyType : DEVPROPTYPE* out -> "int"
; PropertyBuffer : BYTE* optional, out -> "var"
; PropertyBufferSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; Flags : DWORD -> "int"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiGetClassPropertyExW(GUID* ClassGuid, DEVPROPKEY* PropertyKey, DEVPROPTYPE* PropertyType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD* RequiredSize, DWORD Flags, LPCWSTR MachineName, void* Reserved)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetClassPropertyExW "SetupDiGetClassPropertyExW" var, var, int, var, int, var, int, wstr, intptr
; res = SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
; ClassGuid : GUID* -> "var"
; PropertyKey : DEVPROPKEY* -> "var"
; PropertyType : DEVPROPTYPE* out -> "int"
; PropertyBuffer : BYTE* optional, out -> "var"
; PropertyBufferSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; Flags : DWORD -> "int"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiGetClassPropertyExW = setupapi.NewProc("SetupDiGetClassPropertyExW")
)

// ClassGuid (GUID*), PropertyKey (DEVPROPKEY*), PropertyType (DEVPROPTYPE* out), PropertyBuffer (BYTE* optional, out), PropertyBufferSize (DWORD), RequiredSize (DWORD* optional, out), Flags (DWORD), MachineName (LPCWSTR optional), Reserved (void* optional)
r1, _, err := procSetupDiGetClassPropertyExW.Call(
	uintptr(ClassGuid),
	uintptr(PropertyKey),
	uintptr(PropertyType),
	uintptr(PropertyBuffer),
	uintptr(PropertyBufferSize),
	uintptr(RequiredSize),
	uintptr(Flags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(MachineName))),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiGetClassPropertyExW(
  ClassGuid: PGUID;   // GUID*
  PropertyKey: Pointer;   // DEVPROPKEY*
  PropertyType: Pointer;   // DEVPROPTYPE* out
  PropertyBuffer: Pointer;   // BYTE* optional, out
  PropertyBufferSize: DWORD;   // DWORD
  RequiredSize: Pointer;   // DWORD* optional, out
  Flags: DWORD;   // DWORD
  MachineName: PWideChar;   // LPCWSTR optional
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiGetClassPropertyExW';
result := DllCall("SETUPAPI\SetupDiGetClassPropertyExW"
    , "Ptr", ClassGuid   ; GUID*
    , "Ptr", PropertyKey   ; DEVPROPKEY*
    , "Ptr", PropertyType   ; DEVPROPTYPE* out
    , "Ptr", PropertyBuffer   ; BYTE* optional, out
    , "UInt", PropertyBufferSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* optional, out
    , "UInt", Flags   ; DWORD
    , "WStr", MachineName   ; LPCWSTR optional
    , "Ptr", Reserved   ; void* optional
    , "Int")   ; return: BOOL
●SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved) = DLL("SETUPAPI.dll", "bool SetupDiGetClassPropertyExW(void*, void*, void*, void*, dword, void*, dword, char*, void*)")
# 呼び出し: SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
# ClassGuid : GUID* -> "void*"
# PropertyKey : DEVPROPKEY* -> "void*"
# PropertyType : DEVPROPTYPE* out -> "void*"
# PropertyBuffer : BYTE* optional, out -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# Flags : DWORD -> "dword"
# MachineName : LPCWSTR optional -> "char*"
# Reserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。