ホーム › Devices.DeviceAndDriverInstallation › SetupDiGetDeviceInterfacePropertyW
SetupDiGetDeviceInterfacePropertyW
関数デバイスインターフェイスの指定プロパティ値を取得する。
シグネチャ
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiGetDeviceInterfacePropertyW(
HDEVINFO DeviceInfoSet,
SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
const DEVPROPKEY* PropertyKey,
DEVPROPTYPE* PropertyType,
BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize,
DWORD* RequiredSize, // optional
DWORD Flags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DeviceInfoSet | HDEVINFO | in | 対象のデバイス情報セットを指すハンドル。 |
| DeviceInterfaceData | SP_DEVICE_INTERFACE_DATA* | in | プロパティを取得する対象デバイスインターフェイスの構造体。 |
| PropertyKey | DEVPROPKEY* | in | 取得するインターフェイスプロパティを識別するDEVPROPKEY。 |
| PropertyType | DEVPROPTYPE* | out | 取得値のデータ型(DEVPROP_TYPE_*)を受け取るポインタ。 |
| PropertyBuffer | BYTE* | outoptional | プロパティ値を受け取るバッファ。サイズ照会時はNULL可。 |
| PropertyBufferSize | DWORD | in | PropertyBufferのバイトサイズ。 |
| RequiredSize | DWORD* | outoptional | 値に必要なバイト数を受け取るポインタ。不足判定に使う。NULL可。 |
| Flags | DWORD | in | 予約済み。0を指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiGetDeviceInterfacePropertyW(
HDEVINFO DeviceInfoSet,
SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
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 SetupDiGetDeviceInterfacePropertyW(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInterfaceData, // SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInterfaceData As IntPtr, ' SP_DEVICE_INTERFACE_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
' DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
' PropertyKey : DEVPROPKEY*
' PropertyType : DEVPROPTYPE* out
' PropertyBuffer : BYTE* optional, out
' PropertyBufferSize : DWORD
' RequiredSize : DWORD* optional, out
' Flags : DWORD
Declare PtrSafe Function SetupDiGetDeviceInterfacePropertyW Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInterfaceData 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
SetupDiGetDeviceInterfacePropertyW = ctypes.windll.setupapi.SetupDiGetDeviceInterfacePropertyW
SetupDiGetDeviceInterfacePropertyW.restype = wintypes.BOOL
SetupDiGetDeviceInterfacePropertyW.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInterfaceData : SP_DEVICE_INTERFACE_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')
SetupDiGetDeviceInterfacePropertyW = Fiddle::Function.new(
lib['SetupDiGetDeviceInterfacePropertyW'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
DeviceInfoSet: isize, // HDEVINFO
DeviceInterfaceData: *mut SP_DEVICE_INTERFACE_DATA, // SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(IntPtr DeviceInfoSet, IntPtr DeviceInterfaceData, IntPtr PropertyKey, out uint PropertyType, IntPtr PropertyBuffer, uint PropertyBufferSize, IntPtr RequiredSize, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetDeviceInterfacePropertyW' -Namespace Win32 -PassThru
# $api::SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)#uselib "SETUPAPI.dll"
#func global SetupDiGetDeviceInterfacePropertyW "SetupDiGetDeviceInterfacePropertyW" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiGetDeviceInterfacePropertyW DeviceInfoSet, varptr(DeviceInterfaceData), varptr(PropertyKey), varptr(PropertyType), varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize), Flags ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW "SetupDiGetDeviceInterfacePropertyW" sptr, var, var, var, var, int, var, int ; res = SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_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 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiGetDeviceInterfacePropertyW "SetupDiGetDeviceInterfacePropertyW" sptr, sptr, sptr, sptr, sptr, int, sptr, int ; res = SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, varptr(DeviceInterfaceData), varptr(PropertyKey), varptr(PropertyType), varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize), Flags) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "sptr" ; PropertyKey : DEVPROPKEY* -> "sptr" ; PropertyType : DEVPROPTYPE* out -> "sptr" ; PropertyBuffer : BYTE* optional, out -> "sptr" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "sptr" ; Flags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiGetDeviceInterfacePropertyW(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData, DEVPROPKEY* PropertyKey, DEVPROPTYPE* PropertyType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD* RequiredSize, DWORD Flags) #uselib "SETUPAPI.dll" #cfunc global SetupDiGetDeviceInterfacePropertyW "SetupDiGetDeviceInterfacePropertyW" intptr, var, var, var, var, int, var, int ; res = SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData, DEVPROPKEY* PropertyKey, DEVPROPTYPE* PropertyType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD* RequiredSize, DWORD Flags) #uselib "SETUPAPI.dll" #cfunc global SetupDiGetDeviceInterfacePropertyW "SetupDiGetDeviceInterfacePropertyW" intptr, intptr, intptr, intptr, intptr, int, intptr, int ; res = SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, varptr(DeviceInterfaceData), varptr(PropertyKey), varptr(PropertyType), varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize), Flags) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "intptr" ; PropertyKey : DEVPROPKEY* -> "intptr" ; PropertyType : DEVPROPTYPE* out -> "intptr" ; 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")
procSetupDiGetDeviceInterfacePropertyW = setupapi.NewProc("SetupDiGetDeviceInterfacePropertyW")
)
// DeviceInfoSet (HDEVINFO), DeviceInterfaceData (SP_DEVICE_INTERFACE_DATA*), PropertyKey (DEVPROPKEY*), PropertyType (DEVPROPTYPE* out), PropertyBuffer (BYTE* optional, out), PropertyBufferSize (DWORD), RequiredSize (DWORD* optional, out), Flags (DWORD)
r1, _, err := procSetupDiGetDeviceInterfacePropertyW.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInterfaceData),
uintptr(PropertyKey),
uintptr(PropertyType),
uintptr(PropertyBuffer),
uintptr(PropertyBufferSize),
uintptr(RequiredSize),
uintptr(Flags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiGetDeviceInterfacePropertyW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInterfaceData: Pointer; // SP_DEVICE_INTERFACE_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 'SetupDiGetDeviceInterfacePropertyW';result := DllCall("SETUPAPI\SetupDiGetDeviceInterfacePropertyW"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInterfaceData ; SP_DEVICE_INTERFACE_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●SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags) = DLL("SETUPAPI.dll", "bool SetupDiGetDeviceInterfacePropertyW(int, void*, void*, void*, void*, dword, void*, dword)")
# 呼び出し: SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
DeviceInfoSet: isize, // HDEVINFO
DeviceInterfaceData: [*c]SP_DEVICE_INTERFACE_DATA, // SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
DeviceInfoSet: int, # HDEVINFO
DeviceInterfaceData: ptr SP_DEVICE_INTERFACE_DATA, # SP_DEVICE_INTERFACE_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: "SetupDiGetDeviceInterfacePropertyW", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupDiGetDeviceInterfacePropertyW(
ptrdiff_t DeviceInfoSet, // HDEVINFO
SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData, // SP_DEVICE_INTERFACE_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((:SetupDiGetDeviceInterfacePropertyW, "SETUPAPI.dll"), stdcall, Int32,
(Int, Ptr{SP_DEVICE_INTERFACE_DATA}, Ptr{DEVPROPKEY}, Ptr{UInt32}, Ptr{UInt8}, UInt32, Ptr{UInt32}, UInt32),
DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> Ptr{SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
intptr_t DeviceInfoSet,
void* DeviceInterfaceData,
void* PropertyKey,
uint32_t* PropertyType,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize,
uint32_t* RequiredSize,
uint32_t Flags);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
-- DeviceInfoSet : HDEVINFO
-- DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW = lib.func('__stdcall', 'SetupDiGetDeviceInterfacePropertyW', 'int32_t', ['intptr_t', 'void *', 'void *', 'uint32_t *', 'uint8_t *', 'uint32_t', 'uint32_t *', 'uint32_t']);
// SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInterfaceData : SP_DEVICE_INTERFACE_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", {
SetupDiGetDeviceInterfacePropertyW: { parameters: ["isize", "pointer", "pointer", "pointer", "pointer", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
intptr_t DeviceInfoSet,
void* DeviceInterfaceData,
void* PropertyKey,
uint32_t* PropertyType,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize,
uint32_t* RequiredSize,
uint32_t Flags);
C, "SETUPAPI.dll");
// $ffi->SetupDiGetDeviceInterfacePropertyW(DeviceInfoSet, DeviceInterfaceData, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, RequiredSize, Flags);
// DeviceInfoSet : HDEVINFO
// DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
long DeviceInfoSet, // HDEVINFO
Pointer DeviceInterfaceData, // SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW = SetupDiGetDeviceInterfacePropertyW(
DeviceInfoSet : LibC::SSizeT, # HDEVINFO
DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*, # SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyWNative = Int32 Function(IntPtr, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>, Uint32, Pointer<Uint32>, Uint32);
typedef SetupDiGetDeviceInterfacePropertyWDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Uint8>, int, Pointer<Uint32>, int);
final SetupDiGetDeviceInterfacePropertyW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiGetDeviceInterfacePropertyWNative, SetupDiGetDeviceInterfacePropertyWDart>('SetupDiGetDeviceInterfacePropertyW');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInterfaceData : SP_DEVICE_INTERFACE_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 SetupDiGetDeviceInterfacePropertyW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInterfaceData: Pointer; // SP_DEVICE_INTERFACE_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 'SetupDiGetDeviceInterfacePropertyW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiGetDeviceInterfacePropertyW"
c_SetupDiGetDeviceInterfacePropertyW :: CIntPtr -> Ptr () -> Ptr () -> Ptr Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> Word32 -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInterfaceData : SP_DEVICE_INTERFACE_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 setupdigetdeviceinterfacepropertyw =
foreign "SetupDiGetDeviceInterfacePropertyW"
(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 *)
(* DeviceInterfaceData : SP_DEVICE_INTERFACE_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 ("SetupDiGetDeviceInterfacePropertyW" setup-di-get-device-interface-property-w :convention :stdcall) :int32
(device-info-set :int64) ; HDEVINFO
(device-interface-data :pointer) ; SP_DEVICE_INTERFACE_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 $SetupDiGetDeviceInterfacePropertyW = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiGetDeviceInterfacePropertyW(LPARAM DeviceInfoSet, LPVOID DeviceInterfaceData, LPVOID PropertyKey, LPVOID PropertyType, LPVOID PropertyBuffer, DWORD PropertyBufferSize, LPVOID RequiredSize, DWORD Flags)');
# my $ret = $SetupDiGetDeviceInterfacePropertyW->Call($DeviceInfoSet, $DeviceInterfaceData, $PropertyKey, $PropertyType, $PropertyBuffer, $PropertyBufferSize, $RequiredSize, $Flags);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInterfaceData : SP_DEVICE_INTERFACE_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 を使用。