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プロパティを取得する対象クラスのGUID。
PropertyKeyDEVPROPKEY*in取得するクラスプロパティを識別するDEVPROPKEY。
PropertyTypeDEVPROPTYPE*out取得値のデータ型(DEVPROP_TYPE_*)を受け取るポインタ。
PropertyBufferBYTE*outoptionalプロパティ値を受け取るバッファ。サイズ照会時はNULL可。
PropertyBufferSizeDWORDinPropertyBufferのバイトサイズ。
RequiredSizeDWORD*outoptional値に必要なバイト数を受け取るポインタ。不足判定に使う。NULL可。
FlagsDWORDin対象クラス種別フラグ。DICLASSPROP_INSTALLERかDICLASSPROP_INTERFACEを指定する。
MachineNameLPCWSTRinoptional対象リモートコンピュータ名(Unicode)。NULL指定でローカルマシンを対象とする。
Reservedvoid*optional予約済み。NULLを指定する。

戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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), varptr(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, var, 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 -> "var"
; 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, var, 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 -> "var"
; 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)。
const std = @import("std");

extern "setupapi" fn SetupDiGetClassPropertyExW(
    ClassGuid: [*c]GUID, // GUID*
    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
    MachineName: [*c]const u16, // LPCWSTR optional
    Reserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
proc SetupDiGetClassPropertyExW(
    ClassGuid: ptr GUID,  # GUID*
    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
    MachineName: WideCString,  # LPCWSTR optional
    Reserved: pointer  # void* optional
): int32 {.importc: "SetupDiGetClassPropertyExW", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupDiGetClassPropertyExW(
    GUID* ClassGuid,   // GUID*
    DEVPROPKEY* PropertyKey,   // DEVPROPKEY*
    uint* PropertyType,   // DEVPROPTYPE* out
    ubyte* PropertyBuffer,   // BYTE* optional, out
    uint PropertyBufferSize,   // DWORD
    uint* RequiredSize,   // DWORD* optional, out
    uint Flags,   // DWORD
    const(wchar)* MachineName,   // LPCWSTR optional
    void* Reserved   // void* optional
);
ccall((:SetupDiGetClassPropertyExW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{GUID}, Ptr{DEVPROPKEY}, Ptr{UInt32}, Ptr{UInt8}, UInt32, Ptr{UInt32}, UInt32, Cwstring, Ptr{Cvoid}),
      ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
# ClassGuid : GUID* -> Ptr{GUID}
# 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
# MachineName : LPCWSTR optional -> Cwstring
# Reserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiGetClassPropertyExW(
    void* ClassGuid,
    void* PropertyKey,
    uint32_t* PropertyType,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    uint32_t* RequiredSize,
    uint32_t Flags,
    const uint16_t* MachineName,
    void* Reserved);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiGetClassPropertyExW = lib.func('__stdcall', 'SetupDiGetClassPropertyExW', 'int32_t', ['void *', 'void *', 'uint32_t *', 'uint8_t *', 'uint32_t', 'uint32_t *', 'uint32_t', 'str16', 'void *']);
// SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
// ClassGuid : GUID* -> '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'
// MachineName : LPCWSTR optional -> 'str16'
// Reserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiGetClassPropertyExW: { parameters: ["pointer", "pointer", "pointer", "pointer", "u32", "pointer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved)
// ClassGuid : GUID* -> "pointer"
// PropertyKey : DEVPROPKEY* -> "pointer"
// PropertyType : DEVPROPTYPE* out -> "pointer"
// PropertyBuffer : BYTE* optional, out -> "pointer"
// PropertyBufferSize : DWORD -> "u32"
// RequiredSize : DWORD* optional, out -> "pointer"
// Flags : DWORD -> "u32"
// MachineName : LPCWSTR optional -> "buffer"
// Reserved : void* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiGetClassPropertyExW(
    void* ClassGuid,
    void* PropertyKey,
    uint32_t* PropertyType,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    uint32_t* RequiredSize,
    uint32_t Flags,
    const uint16_t* MachineName,
    void* Reserved);
C, "SETUPAPI.dll");
// $ffi->SetupDiGetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags, MachineName, Reserved);
// 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
// 構造体/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 SetupDiGetClassPropertyExW(
        Pointer ClassGuid,   // GUID*
        Pointer PropertyKey,   // DEVPROPKEY*
        IntByReference PropertyType,   // DEVPROPTYPE* out
        byte[] PropertyBuffer,   // BYTE* optional, out
        int PropertyBufferSize,   // DWORD
        IntByReference RequiredSize,   // DWORD* optional, out
        int Flags,   // DWORD
        WString MachineName,   // LPCWSTR optional
        Pointer Reserved   // void* optional
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiGetClassPropertyExW = SetupDiGetClassPropertyExW(
    ClassGuid : GUID*,   # GUID*
    PropertyKey : DEVPROPKEY*,   # DEVPROPKEY*
    PropertyType : UInt32*,   # DEVPROPTYPE* out
    PropertyBuffer : UInt8*,   # BYTE* optional, out
    PropertyBufferSize : UInt32,   # DWORD
    RequiredSize : UInt32*,   # DWORD* optional, out
    Flags : UInt32,   # DWORD
    MachineName : UInt16*,   # LPCWSTR optional
    Reserved : Void*   # void* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupDiGetClassPropertyExWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>, Uint32, Pointer<Uint32>, Uint32, Pointer<Utf16>, Pointer<Void>);
typedef SetupDiGetClassPropertyExWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>, int, Pointer<Uint32>, int, Pointer<Utf16>, Pointer<Void>);
final SetupDiGetClassPropertyExW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiGetClassPropertyExWNative, SetupDiGetClassPropertyExWDart>('SetupDiGetClassPropertyExW');
// ClassGuid : GUID* -> 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
// MachineName : LPCWSTR optional -> Pointer<Utf16>
// Reserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiGetClassPropertyExW"
  c_SetupDiGetClassPropertyExW :: Ptr () -> Ptr () -> Ptr Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> Word32 -> CWString -> Ptr () -> IO CInt
-- ClassGuid : GUID* -> 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
-- MachineName : LPCWSTR optional -> CWString
-- Reserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdigetclasspropertyexw =
  foreign "SetupDiGetClassPropertyExW"
    ((ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* ClassGuid : GUID* -> (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 *)
(* MachineName : LPCWSTR optional -> (ptr uint16_t) *)
(* Reserved : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupDiGetClassPropertyExW" setup-di-get-class-property-ex-w :convention :stdcall) :int32
  (class-guid :pointer)   ; GUID*
  (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
  (machine-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (reserved :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiGetClassPropertyExW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiGetClassPropertyExW(LPVOID ClassGuid, LPVOID PropertyKey, LPVOID PropertyType, LPVOID PropertyBuffer, DWORD PropertyBufferSize, LPVOID RequiredSize, DWORD Flags, LPCWSTR MachineName, LPVOID Reserved)');
# my $ret = $SetupDiGetClassPropertyExW->Call($ClassGuid, $PropertyKey, $PropertyType, $PropertyBuffer, $PropertyBufferSize, $RequiredSize, $Flags, $MachineName, $Reserved);
# ClassGuid : GUID* -> LPVOID
# PropertyKey : DEVPROPKEY* -> LPVOID
# PropertyType : DEVPROPTYPE* out -> LPVOID
# PropertyBuffer : BYTE* optional, out -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# Flags : DWORD -> DWORD
# MachineName : LPCWSTR optional -> LPCWSTR
# Reserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型