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

SetupDiGetDevicePropertyW

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

シグネチャ

// 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
);

パラメーター

名前方向説明
DeviceInfoSetHDEVINFOin対象のデバイス情報セットを指すハンドル。
DeviceInfoDataSP_DEVINFO_DATA*inプロパティを取得する対象デバイスの構造体。
PropertyKeyDEVPROPKEY*in取得するデバイスプロパティを識別するDEVPROPKEY。
PropertyTypeDEVPROPTYPE*out取得値のデータ型(DEVPROP_TYPE_*)を受け取るポインタ。
PropertyBufferBYTE*outoptionalプロパティ値を受け取るバッファ。サイズ照会時はNULL可。
PropertyBufferSizeDWORDinPropertyBufferのバイトサイズ。
RequiredSizeDWORD*outoptional値に必要なバイト数を受け取るポインタ。不足判定に使う。NULL可。
FlagsDWORDin予約済み。0を指定する。

戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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), varptr(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, var, 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 -> "var"
; 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, var, var, var, 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 -> "var"
; PropertyBuffer : BYTE* optional, out -> "var"
; PropertyBufferSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; Flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。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   // BOOL
function 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)。
const std = @import("std");

extern "setupapi" fn SetupDiGetDevicePropertyW(
    DeviceInfoSet: isize, // HDEVINFO
    DeviceInfoData: [*c]SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
    PropertyKey: [*c]DEVPROPKEY, // DEVPROPKEY*
    PropertyType: [*c]u32, // DEVPROPTYPE* out
    PropertyBuffer: [*c]u8, // BYTE* optional, out
    PropertyBufferSize: u32, // DWORD
    RequiredSize: [*c]u32, // DWORD* optional, out
    Flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SetupDiGetDevicePropertyW(
    DeviceInfoSet: int,  # HDEVINFO
    DeviceInfoData: ptr SP_DEVINFO_DATA,  # SP_DEVINFO_DATA*
    PropertyKey: ptr DEVPROPKEY,  # DEVPROPKEY*
    PropertyType: ptr uint32,  # DEVPROPTYPE* out
    PropertyBuffer: ptr uint8,  # BYTE* optional, out
    PropertyBufferSize: uint32,  # DWORD
    RequiredSize: ptr uint32,  # DWORD* optional, out
    Flags: uint32  # DWORD
): int32 {.importc: "SetupDiGetDevicePropertyW", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupDiGetDevicePropertyW(
    ptrdiff_t DeviceInfoSet,   // HDEVINFO
    SP_DEVINFO_DATA* DeviceInfoData,   // SP_DEVINFO_DATA*
    DEVPROPKEY* PropertyKey,   // DEVPROPKEY*
    uint* PropertyType,   // DEVPROPTYPE* out
    ubyte* PropertyBuffer,   // BYTE* optional, out
    uint PropertyBufferSize,   // DWORD
    uint* RequiredSize,   // DWORD* optional, out
    uint Flags   // DWORD
);
ccall((:SetupDiGetDevicePropertyW, "SETUPAPI.dll"), stdcall, Int32,
      (Int, Ptr{SP_DEVINFO_DATA}, Ptr{DEVPROPKEY}, Ptr{UInt32}, Ptr{UInt8}, UInt32, Ptr{UInt32}, UInt32),
      DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInfoData : SP_DEVINFO_DATA* -> Ptr{SP_DEVINFO_DATA}
# PropertyKey : DEVPROPKEY* -> Ptr{DEVPROPKEY}
# PropertyType : DEVPROPTYPE* out -> Ptr{UInt32}
# PropertyBuffer : BYTE* optional, out -> Ptr{UInt8}
# PropertyBufferSize : DWORD -> UInt32
# RequiredSize : DWORD* optional, out -> Ptr{UInt32}
# Flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiGetDevicePropertyW(
    intptr_t DeviceInfoSet,
    void* DeviceInfoData,
    void* PropertyKey,
    uint32_t* PropertyType,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    uint32_t* RequiredSize,
    uint32_t Flags);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
-- DeviceInfoSet : HDEVINFO
-- DeviceInfoData : SP_DEVINFO_DATA*
-- PropertyKey : DEVPROPKEY*
-- PropertyType : DEVPROPTYPE* out
-- PropertyBuffer : BYTE* optional, out
-- PropertyBufferSize : DWORD
-- RequiredSize : DWORD* optional, out
-- Flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiGetDevicePropertyW = lib.func('__stdcall', 'SetupDiGetDevicePropertyW', 'int32_t', ['intptr_t', 'void *', 'void *', 'uint32_t *', 'uint8_t *', 'uint32_t', 'uint32_t *', 'uint32_t']);
// SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* -> 'void *'
// PropertyKey : DEVPROPKEY* -> 'void *'
// PropertyType : DEVPROPTYPE* out -> 'uint32_t *'
// PropertyBuffer : BYTE* optional, out -> 'uint8_t *'
// PropertyBufferSize : DWORD -> 'uint32_t'
// RequiredSize : DWORD* optional, out -> 'uint32_t *'
// Flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiGetDevicePropertyW: { parameters: ["isize", "pointer", "pointer", "pointer", "pointer", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* -> "pointer"
// PropertyKey : DEVPROPKEY* -> "pointer"
// PropertyType : DEVPROPTYPE* out -> "pointer"
// PropertyBuffer : BYTE* optional, out -> "pointer"
// PropertyBufferSize : DWORD -> "u32"
// RequiredSize : DWORD* optional, out -> "pointer"
// Flags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiGetDevicePropertyW(
    intptr_t DeviceInfoSet,
    void* DeviceInfoData,
    void* PropertyKey,
    uint32_t* PropertyType,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    uint32_t* RequiredSize,
    uint32_t Flags);
C, "SETUPAPI.dll");
// $ffi->SetupDiGetDevicePropertyW(DeviceInfoSet, DeviceInfoData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags);
// DeviceInfoSet : HDEVINFO
// DeviceInfoData : SP_DEVINFO_DATA*
// PropertyKey : DEVPROPKEY*
// PropertyType : DEVPROPTYPE* out
// PropertyBuffer : BYTE* optional, out
// PropertyBufferSize : DWORD
// RequiredSize : DWORD* optional, out
// Flags : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Setupapi extends StdCallLibrary {
    Setupapi INSTANCE = Native.load("setupapi", Setupapi.class);
    boolean SetupDiGetDevicePropertyW(
        long DeviceInfoSet,   // HDEVINFO
        Pointer DeviceInfoData,   // SP_DEVINFO_DATA*
        Pointer PropertyKey,   // DEVPROPKEY*
        IntByReference PropertyType,   // DEVPROPTYPE* out
        byte[] PropertyBuffer,   // BYTE* optional, out
        int PropertyBufferSize,   // DWORD
        IntByReference RequiredSize,   // DWORD* optional, out
        int Flags   // DWORD
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiGetDevicePropertyW = SetupDiGetDevicePropertyW(
    DeviceInfoSet : LibC::SSizeT,   # HDEVINFO
    DeviceInfoData : SP_DEVINFO_DATA*,   # SP_DEVINFO_DATA*
    PropertyKey : DEVPROPKEY*,   # DEVPROPKEY*
    PropertyType : UInt32*,   # DEVPROPTYPE* out
    PropertyBuffer : UInt8*,   # BYTE* optional, out
    PropertyBufferSize : UInt32,   # DWORD
    RequiredSize : UInt32*,   # DWORD* optional, out
    Flags : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupDiGetDevicePropertyWNative = Int32 Function(IntPtr, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>, Uint32, Pointer<Uint32>, Uint32);
typedef SetupDiGetDevicePropertyWDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>, int, Pointer<Uint32>, int);
final SetupDiGetDevicePropertyW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiGetDevicePropertyWNative, SetupDiGetDevicePropertyWDart>('SetupDiGetDevicePropertyW');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* -> Pointer<Void>
// PropertyKey : DEVPROPKEY* -> Pointer<Void>
// PropertyType : DEVPROPTYPE* out -> Pointer<Uint32>
// PropertyBuffer : BYTE* optional, out -> Pointer<Uint8>
// PropertyBufferSize : DWORD -> Uint32
// RequiredSize : DWORD* optional, out -> Pointer<Uint32>
// Flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function 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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiGetDevicePropertyW"
  c_SetupDiGetDevicePropertyW :: CIntPtr -> Ptr () -> Ptr () -> Ptr Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> Word32 -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* -> Ptr ()
-- PropertyKey : DEVPROPKEY* -> Ptr ()
-- PropertyType : DEVPROPTYPE* out -> Ptr Word32
-- PropertyBuffer : BYTE* optional, out -> Ptr Word8
-- PropertyBufferSize : DWORD -> Word32
-- RequiredSize : DWORD* optional, out -> Ptr Word32
-- Flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdigetdevicepropertyw =
  foreign "SetupDiGetDevicePropertyW"
    (intptr_t @-> (ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> uint32_t @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* -> (ptr void) *)
(* PropertyKey : DEVPROPKEY* -> (ptr void) *)
(* PropertyType : DEVPROPTYPE* out -> (ptr uint32_t) *)
(* PropertyBuffer : BYTE* optional, out -> (ptr uint8_t) *)
(* PropertyBufferSize : DWORD -> uint32_t *)
(* RequiredSize : DWORD* optional, out -> (ptr uint32_t) *)
(* Flags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupDiGetDevicePropertyW" setup-di-get-device-property-w :convention :stdcall) :int32
  (device-info-set :int64)   ; HDEVINFO
  (device-info-data :pointer)   ; SP_DEVINFO_DATA*
  (property-key :pointer)   ; DEVPROPKEY*
  (property-type :pointer)   ; DEVPROPTYPE* out
  (property-buffer :pointer)   ; BYTE* optional, out
  (property-buffer-size :uint32)   ; DWORD
  (required-size :pointer)   ; DWORD* optional, out
  (flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiGetDevicePropertyW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiGetDevicePropertyW(LPARAM DeviceInfoSet, LPVOID DeviceInfoData, LPVOID PropertyKey, LPVOID PropertyType, LPVOID PropertyBuffer, DWORD PropertyBufferSize, LPVOID RequiredSize, DWORD Flags)');
# my $ret = $SetupDiGetDevicePropertyW->Call($DeviceInfoSet, $DeviceInfoData, $PropertyKey, $PropertyType, $PropertyBuffer, $PropertyBufferSize, $RequiredSize, $Flags);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* -> LPVOID
# PropertyKey : DEVPROPKEY* -> LPVOID
# PropertyType : DEVPROPTYPE* out -> LPVOID
# PropertyBuffer : BYTE* optional, out -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# Flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型