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

SetupDiGetCustomDevicePropertyW

関数
デバイスの指定したカスタムプロパティを取得する。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupDiGetCustomDevicePropertyW(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,
    LPCWSTR CustomPropertyName,
    DWORD Flags,
    DWORD* PropertyRegDataType,   // optional
    BYTE* PropertyBuffer,
    DWORD PropertyBufferSize,
    DWORD* RequiredSize   // optional
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInfoDataSP_DEVINFO_DATA*in
CustomPropertyNameLPCWSTRin
FlagsDWORDin
PropertyRegDataTypeDWORD*outoptional
PropertyBufferBYTE*out
PropertyBufferSizeDWORDin
RequiredSizeDWORD*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupDiGetCustomDevicePropertyW(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,
    LPCWSTR CustomPropertyName,
    DWORD Flags,
    DWORD* PropertyRegDataType,   // optional
    BYTE* PropertyBuffer,
    DWORD PropertyBufferSize,
    DWORD* RequiredSize   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetCustomDevicePropertyW(
    IntPtr DeviceInfoSet,   // HDEVINFO
    IntPtr DeviceInfoData,   // SP_DEVINFO_DATA*
    [MarshalAs(UnmanagedType.LPWStr)] string CustomPropertyName,   // LPCWSTR
    uint Flags,   // DWORD
    IntPtr PropertyRegDataType,   // DWORD* optional, out
    IntPtr PropertyBuffer,   // BYTE* out
    uint PropertyBufferSize,   // DWORD
    IntPtr RequiredSize   // DWORD* optional, out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiGetCustomDevicePropertyW(
    DeviceInfoSet As IntPtr,   ' HDEVINFO
    DeviceInfoData As IntPtr,   ' SP_DEVINFO_DATA*
    <MarshalAs(UnmanagedType.LPWStr)> CustomPropertyName As String,   ' LPCWSTR
    Flags As UInteger,   ' DWORD
    PropertyRegDataType As IntPtr,   ' DWORD* optional, out
    PropertyBuffer As IntPtr,   ' BYTE* out
    PropertyBufferSize As UInteger,   ' DWORD
    RequiredSize As IntPtr   ' DWORD* optional, out
) As Boolean
End Function
' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
' CustomPropertyName : LPCWSTR
' Flags : DWORD
' PropertyRegDataType : DWORD* optional, out
' PropertyBuffer : BYTE* out
' PropertyBufferSize : DWORD
' RequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupDiGetCustomDevicePropertyW Lib "setupapi" ( _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInfoData As LongPtr, _
    ByVal CustomPropertyName As LongPtr, _
    ByVal Flags As Long, _
    ByVal PropertyRegDataType As LongPtr, _
    ByVal PropertyBuffer As LongPtr, _
    ByVal PropertyBufferSize As Long, _
    ByVal RequiredSize As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiGetCustomDevicePropertyW = setupapi.NewProc("SetupDiGetCustomDevicePropertyW")
)

// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA*), CustomPropertyName (LPCWSTR), Flags (DWORD), PropertyRegDataType (DWORD* optional, out), PropertyBuffer (BYTE* out), PropertyBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupDiGetCustomDevicePropertyW.Call(
	uintptr(DeviceInfoSet),
	uintptr(DeviceInfoData),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(CustomPropertyName))),
	uintptr(Flags),
	uintptr(PropertyRegDataType),
	uintptr(PropertyBuffer),
	uintptr(PropertyBufferSize),
	uintptr(RequiredSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiGetCustomDevicePropertyW(
  DeviceInfoSet: NativeInt;   // HDEVINFO
  DeviceInfoData: Pointer;   // SP_DEVINFO_DATA*
  CustomPropertyName: PWideChar;   // LPCWSTR
  Flags: DWORD;   // DWORD
  PropertyRegDataType: Pointer;   // DWORD* optional, out
  PropertyBuffer: Pointer;   // BYTE* out
  PropertyBufferSize: DWORD;   // DWORD
  RequiredSize: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiGetCustomDevicePropertyW';
result := DllCall("SETUPAPI\SetupDiGetCustomDevicePropertyW"
    , "Ptr", DeviceInfoSet   ; HDEVINFO
    , "Ptr", DeviceInfoData   ; SP_DEVINFO_DATA*
    , "WStr", CustomPropertyName   ; LPCWSTR
    , "UInt", Flags   ; DWORD
    , "Ptr", PropertyRegDataType   ; DWORD* optional, out
    , "Ptr", PropertyBuffer   ; BYTE* out
    , "UInt", PropertyBufferSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●SetupDiGetCustomDevicePropertyW(DeviceInfoSet, DeviceInfoData, CustomPropertyName, Flags, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupDiGetCustomDevicePropertyW(int, void*, char*, dword, void*, void*, dword, void*)")
# 呼び出し: SetupDiGetCustomDevicePropertyW(DeviceInfoSet, DeviceInfoData, CustomPropertyName, Flags, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* -> "void*"
# CustomPropertyName : LPCWSTR -> "char*"
# Flags : DWORD -> "dword"
# PropertyRegDataType : DWORD* optional, out -> "void*"
# PropertyBuffer : BYTE* out -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。