SetupDiGetDeviceRegistryPropertyW
関数シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupDiGetDeviceRegistryPropertyW(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
SETUP_DI_REGISTRY_PROPERTY Property,
DWORD* PropertyRegDataType, // optional
BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize,
DWORD* RequiredSize // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| DeviceInfoSet | HDEVINFO | in | Plug and Play プロパティを取得する対象のデバイスを表すデバイス情報要素を含む、デバイス情報セットへのハンドル。 | ||||||||||||||||||||||
| DeviceInfoData | SP_DEVINFO_DATA* | in | DeviceInfoSet 内のデバイス情報要素を指定する SP_DEVINFO_DATA 構造体へのポインター。 | ||||||||||||||||||||||
| Property | SETUP_DI_REGISTRY_PROPERTY | in | 取得するプロパティを指定する、次のいずれかの値です: SPDRP_ADDRESSデバイスのアドレスを取得します。 SPDRP_BUSNUMBERデバイスのバス番号を取得します。 SPDRP_BUSTYPEGUIDデバイスのバスの種類を表す GUID を取得します。 SPDRP_CAPABILITIES次の CM_DEVCAP_Xxx フラグのビット単位の OR を DWORD で取得します。これらのフラグが表すデバイスの機能は、DEVICE_CAPABILITIES 構造体のメンバーが表すデバイスの機能に対応します。CM_DEVCAP_Xxx 定数は Cfgmgr32.h. で定義されています。
SPDRP_CHARACTERISTICSデバイスの特性フラグのビット単位の OR を DWORD で取得します。これらのフラグは Wdm.h および Ntddk.h で定義されています。フラグの説明については、IoCreateDevice 関数の DeviceCharacteristics パラメーターを参照してください。 SPDRP_CLASSデバイスのデバイスセットアップクラスを含む REG_SZ 文字列を取得します。 SPDRP_CLASSGUIDデバイスのデバイスセットアップクラスを表す GUID を含む REG_SZ 文字列を取得します。 SPDRP_COMPATIBLEIDSデバイスの互換 ID の一覧を含む REG_MULTI_SZ 文字列を取得します。互換 ID については、デバイス識別文字列 を参照してください。 SPDRP_CONFIGFLAGSデバイスの構成フラグのビット単位の OR を DWORD 値で取得します。構成フラグは、Regstr.h で定義されている CONFIGFLAG_Xxx ビットマスクで表されます。 SPDRP_DEVICE_POWER_DATA(Windows XP 以降) デバイスの電源管理情報を含む CM_POWER_DATA 構造体を取得します。 SPDRP_DEVICEDESCデバイスの説明を含む REG_SZ 文字列を取得します。 SPDRP_DEVTYPEデバイスの種類を表す DWORD 値を取得します。詳細については、デバイスの種類の指定 を参照してください。 SPDRP_DRIVERデバイスのソフトウェアキー(ドライバーキーと呼ばれることもあります) を識別する文字列を取得します。ドライバーキーの詳細については、デバイスとドライバーのレジストリツリーとキー を参照してください。 SPDRP_ENUMERATOR_NAMEデバイスの列挙子の名前を含む REG_SZ 文字列を取得します。 SPDRP_EXCLUSIVEユーザーがデバイスを排他的に使用できるかどうかを示す DWORD 値を取得します。排他的な使用が許可されている場合は 1、それ以外の場合は 0 が返されます。詳細については、IoCreateDevice を参照してください。 SPDRP_FRIENDLYNAMEデバイスのフレンドリ名を含む REG_SZ 文字列を取得します。 SPDRP_HARDWAREIDデバイスのハードウェア ID の一覧を含む REG_MULTI_SZ 文字列を取得します。ハードウェア ID については、デバイス識別文字列 を参照してください。 SPDRP_INSTALL_STATE(Windows XP 以降) デバイスのインストール状態を示す DWORD 値を取得します。インストール状態は、Cfgmgr32.h で定義されている CM_INSTALL_STATE_Xxx 値のいずれかで表されます。CM_INSTALL_STATE_Xxx 値は、DEVICE_INSTALL_STATE 列挙型の値に対応します。 SPDRP_LEGACYBUSTYPEデバイスのレガシバスの種類を INTERFACE_TYPE 値 (Wdm.h および Ntddk.h で定義) として取得します。 SPDRP_LOCATION_INFORMATIONデバイスのハードウェア上の位置を含む REG_SZ 文字列を取得します。 SPDRP_LOCATION_PATHS(Windows Server 2003 以降) デバイスツリー内でのデバイスの位置を表す REG_MULTI_SZ 文字列を取得します。 SPDRP_LOWERFILTERSデバイスの下位フィルタードライバーの名前を含む REG_MULTI_SZ 文字列を取得します。 SPDRP_MFGデバイスの製造元の名前を含む REG_SZ 文字列を取得します。 SPDRP_PHYSICAL_DEVICE_OBJECT_NAMEデバイスの PDO に関連付けられている名前を含む REG_SZ 文字列を取得します。詳細については、IoCreateDevice を参照してください。 SPDRP_REMOVAL_POLICY(Windows XP 以降) デバイスの現在の取り外しポリシーを、Cfgmgr32.h で定義されている CM_REMOVAL_POLICY_Xxx 値のいずれかを含む DWORD として取得します。 SPDRP_REMOVAL_POLICY_HW_DEFAULT(Windows XP 以降) ハードウェアで指定されたデバイスの既定の取り外しポリシーを、Cfgmgr32.h で定義されている CM_REMOVAL_POLICY_Xxx 値のいずれかを含む DWORD として取得します。 SPDRP_REMOVAL_POLICY_OVERRIDE(Windows XP 以降) デバイスのオーバーライド用取り外しポリシー (存在する場合) を、Cfgmgr32.h で定義されている CM_REMOVAL_POLICY_Xxx 値のいずれかを含む DWORD としてレジストリから取得します。 SPDRP_SECURITYデバイスの SECURITY_DESCRIPTOR 構造体を取得します。 SPDRP_SECURITY_SDSデバイスのセキュリティ記述子を含む REG_SZ 文字列を取得します。セキュリティ記述子文字列については、セキュリティ記述子定義言語 (Windows) を参照してください。セキュリティ記述子文字列の形式については、セキュリティ記述子定義言語 (Windows) を参照してください。 SPDRP_SERVICEデバイスのサービス名を含む REG_SZ 文字列を取得します。 SPDRP_UI_NUMBERデバイスの DEVICE_CAPABILITIES 構造体の UINumber メンバーの値が設定された DWORD 値を取得します。 SPDRP_UI_NUMBER_DESC_FORMATUINumber 値の表示に使用される書式文字列 (REG_SZ) を取得します。 SPDRP_UPPERFILTERSデバイスの上位フィルタードライバーの名前を含む REG_MULTI_SZ 文字列を取得します。 | ||||||||||||||||||||||
| PropertyRegDataType | DWORD* | outoptional | 取得するプロパティのデータ型を受け取る変数へのポインター。これは標準のレジストリデータ型のいずれかです。このパラメーターは省略可能で、NULL を指定できます。 | ||||||||||||||||||||||
| PropertyBuffer | BYTE* | outoptional | 取得するプロパティを受け取るバッファーへのポインター。このパラメーターに NULL を指定し、PropertyBufferSize にも 0 を指定した場合、関数は必要なバッファーのサイズを RequiredSize に返します。 | ||||||||||||||||||||||
| PropertyBufferSize | DWORD | in | PropertyBuffer バッファーのサイズ (バイト単位)。 | ||||||||||||||||||||||
| RequiredSize | DWORD* | outoptional | 要求されたプロパティのデータを保持するために必要な PropertyBuffer バッファーのサイズ (バイト単位) を受け取る DWORD 型の変数へのポインター。このパラメーターは省略可能で、NULL を指定できます。 - Property.SPDRP_ADDRESSデバイスのアドレスを取得します。 - Property.SPDRP_BUSNUMBERデバイスのバス番号を取得します。 - Property.SPDRP_BUSTYPEGUIDデバイスのバスの種類を表す GUID を取得します。 - Property.SPDRP_CAPABILITIES次の CM_DEVCAP_Xxx フラグのビット単位の OR を DWORD で取得します。これらのフラグが表すデバイスの機能は、DEVICE_CAPABILITIES 構造体のメンバーが表すデバイスの機能に対応します。CM_DEVCAP_Xxx 定数は Cfgmgr32.h. で定義されています。
- Property.SPDRP_CHARACTERISTICSデバイスの特性フラグのビット単位の OR を DWORD で取得します。これらのフラグは Wdm.h および Ntddk.h で定義されています。フラグの説明については、IoCreateDevice 関数の DeviceCharacteristics パラメーターを参照してください。 - Property.SPDRP_CLASSデバイスのデバイスセットアップクラスを含む REG_SZ 文字列を取得します。 - Property.SPDRP_CLASSGUIDデバイスのデバイスセットアップクラスを表す GUID を含む REG_SZ 文字列を取得します。 - Property.SPDRP_COMPATIBLEIDSデバイスの互換 ID の一覧を含む REG_MULTI_SZ 文字列を取得します。互換 ID については、デバイス識別文字列 を参照してください。 - Property.SPDRP_CONFIGFLAGSデバイスの構成フラグのビット単位の OR を DWORD 値で取得します。構成フラグは、Regstr.h で定義されている CONFIGFLAG_Xxx ビットマスクで表されます。 - Property.SPDRP_DEVICEDESCデバイスの説明を含む REG_SZ 文字列を取得します。 - Property.SPDRP_DEVICE_POWER_DATA(Windows XP 以降) デバイスの電源管理情報を含む CM_POWER_DATA 構造体を取得します。 - Property.SPDRP_DEVTYPEデバイスの種類を表す DWORD 値を取得します。詳細については、デバイスの種類の指定 を参照してください。 - Property.SPDRP_DRIVERデバイスのソフトウェアキー(ドライバーキーと呼ばれることもあります) を識別する文字列を取得します。ドライバーキーの詳細については、デバイスとドライバーのレジストリツリーとキー を参照してください。 - Property.SPDRP_ENUMERATOR_NAMEデバイスの列挙子の名前を含む REG_SZ 文字列を取得します。 - Property.SPDRP_EXCLUSIVEユーザーがデバイスを排他的に使用できるかどうかを示す DWORD 値を取得します。排他的な使用が許可されている場合は 1、それ以外の場合は 0 が返されます。詳細については、IoCreateDevice を参照してください。 - Property.SPDRP_FRIENDLYNAMEデバイスのフレンドリ名を含む REG_SZ 文字列を取得します。 - Property.SPDRP_HARDWAREIDデバイスのハードウェア ID の一覧を含む REG_MULTI_SZ 文字列を取得します。ハードウェア ID については、デバイス識別文字列 を参照してください。 - Property.SPDRP_INSTALL_STATE(Windows XP 以降) デバイスのインストール状態を示す DWORD 値を取得します。インストール状態は、Cfgmgr32.h で定義されている CM_INSTALL_STATE_Xxx 値のいずれかで表されます。CM_INSTALL_STATE_Xxx 値は、DEVICE_INSTALL_STATE 列挙型の値に対応します。 - Property.SPDRP_LEGACYBUSTYPEデバイスのレガシバスの種類を INTERFACE_TYPE 値 (Wdm.h および Ntddk.h で定義) として取得します。 - Property.SPDRP_LOCATION_INFORMATIONデバイスのハードウェア上の位置を含む REG_SZ 文字列を取得します。 - Property.SPDRP_LOCATION_PATHS(Windows Server 2003 以降) デバイスツリー内でのデバイスの位置を表す REG_MULTI_SZ 文字列を取得します。 - Property.SPDRP_LOWERFILTERSデバイスの下位フィルタードライバーの名前を含む REG_MULTI_SZ 文字列を取得します。 - Property.SPDRP_MFGデバイスの製造元の名前を含む REG_SZ 文字列を取得します。 - Property.SPDRP_PHYSICAL_DEVICE_OBJECT_NAMEデバイスの PDO に関連付けられている名前を含む REG_SZ 文字列を取得します。詳細については、IoCreateDevice を参照してください。 - Property.SPDRP_REMOVAL_POLICY(Windows XP 以降) デバイスの現在の取り外しポリシーを、Cfgmgr32.h で定義されている CM_REMOVAL_POLICY_Xxx 値のいずれかを含む DWORD として取得します。 - Property.SPDRP_REMOVAL_POLICY_HW_DEFAULT(Windows XP 以降) ハードウェアで指定されたデバイスの既定の取り外しポリシーを、Cfgmgr32.h で定義されている CM_REMOVAL_POLICY_Xxx 値のいずれかを含む DWORD として取得します。 - Property.SPDRP_REMOVAL_POLICY_OVERRIDE(Windows XP 以降) デバイスのオーバーライド用取り外しポリシー (存在する場合) を、Cfgmgr32.h で定義されている CM_REMOVAL_POLICY_Xxx 値のいずれかを含む DWORD としてレジストリから取得します。 - Property.SPDRP_SECURITYデバイスの SECURITY_DESCRIPTOR 構造体を取得します。 - Property.SPDRP_SECURITY_SDSデバイスのセキュリティ記述子を含む REG_SZ 文字列を取得します。セキュリティ記述子文字列については、セキュリティ記述子定義言語 (Windows) を参照してください。セキュリティ記述子文字列の形式については、セキュリティ記述子定義言語 (Windows) を参照してください。 - Property.SPDRP_SERVICEデバイスのサービス名を含む REG_SZ 文字列を取得します。 - Property.SPDRP_UI_NUMBERデバイスの DEVICE_CAPABILITIES 構造体の UINumber メンバーの値が設定された DWORD 値を取得します。 - Property.SPDRP_UI_NUMBER_DESC_FORMATUINumber 値の表示に使用される書式文字列 (REG_SZ) を取得します。 - Property.SPDRP_UPPERFILTERSデバイスの上位フィルタードライバーの名前を含む REG_MULTI_SZ 文字列を取得します。 |
戻り値の型: BOOL
公式ドキュメント
SetupDiGetDeviceRegistryProperty 関数は、指定された Plug and Play デバイスのプロパティを取得します。(Unicode)
戻り値
呼び出しが成功した場合、SetupDiGetDeviceRegistryProperty は TRUE を返します。それ以外の場合は FALSE を返し、記録されたエラーは GetLastError を呼び出すことで取得できます。要求されたプロパティがデバイスに存在しない場合、またはプロパティのデータが有効でない場合、SetupDiGetDeviceRegistryProperty は ERROR_INVALID_DATA エラーコードを返します。
解説(Remarks)
setupapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SetupDiGetDeviceRegistryProperty を定義しています。エンコードに依存しないエイリアスの使用と、エンコードに依存するコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となる可能性があります。詳細については、関数プロトタイプの規則 を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupDiGetDeviceRegistryPropertyW(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
SETUP_DI_REGISTRY_PROPERTY Property,
DWORD* PropertyRegDataType, // optional
BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize,
DWORD* RequiredSize // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetDeviceRegistryPropertyW(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData, // SP_DEVINFO_DATA*
uint Property, // SETUP_DI_REGISTRY_PROPERTY
IntPtr PropertyRegDataType, // DWORD* optional, out
IntPtr PropertyBuffer, // BYTE* optional, out
uint PropertyBufferSize, // DWORD
IntPtr RequiredSize // DWORD* optional, out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiGetDeviceRegistryPropertyW(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr, ' SP_DEVINFO_DATA*
[Property] As UInteger, ' SETUP_DI_REGISTRY_PROPERTY
PropertyRegDataType As IntPtr, ' DWORD* optional, out
PropertyBuffer As IntPtr, ' BYTE* optional, out
PropertyBufferSize As UInteger, ' DWORD
RequiredSize As IntPtr ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
' Property : SETUP_DI_REGISTRY_PROPERTY
' PropertyRegDataType : DWORD* optional, out
' PropertyBuffer : BYTE* optional, out
' PropertyBufferSize : DWORD
' RequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupDiGetDeviceRegistryPropertyW Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr, _
ByVal Property 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
SetupDiGetDeviceRegistryPropertyW = ctypes.windll.setupapi.SetupDiGetDeviceRegistryPropertyW
SetupDiGetDeviceRegistryPropertyW.restype = wintypes.BOOL
SetupDiGetDeviceRegistryPropertyW.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA*
wintypes.DWORD, # Property : SETUP_DI_REGISTRY_PROPERTY
ctypes.POINTER(wintypes.DWORD), # PropertyRegDataType : DWORD* optional, out
ctypes.POINTER(ctypes.c_ubyte), # PropertyBuffer : BYTE* optional, 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')
SetupDiGetDeviceRegistryPropertyW = Fiddle::Function.new(
lib['SetupDiGetDeviceRegistryPropertyW'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA*
-Fiddle::TYPE_INT, # Property : SETUP_DI_REGISTRY_PROPERTY
Fiddle::TYPE_VOIDP, # PropertyRegDataType : DWORD* optional, out
Fiddle::TYPE_VOIDP, # PropertyBuffer : BYTE* optional, 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 SetupDiGetDeviceRegistryPropertyW(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
Property: u32, // SETUP_DI_REGISTRY_PROPERTY
PropertyRegDataType: *mut u32, // DWORD* optional, out
PropertyBuffer: *mut u8, // BYTE* optional, 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 SetupDiGetDeviceRegistryPropertyW(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, uint Property, IntPtr PropertyRegDataType, IntPtr PropertyBuffer, uint PropertyBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetDeviceRegistryPropertyW' -Namespace Win32 -PassThru
# $api::SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)#uselib "SETUPAPI.dll"
#func global SetupDiGetDeviceRegistryPropertyW "SetupDiGetDeviceRegistryPropertyW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiGetDeviceRegistryPropertyW DeviceInfoSet, varptr(DeviceInfoData), Property, varptr(PropertyRegDataType), varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize) ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "wptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "wptr"
; Property : SETUP_DI_REGISTRY_PROPERTY -> "wptr"
; PropertyRegDataType : DWORD* optional, out -> "wptr"
; PropertyBuffer : BYTE* optional, out -> "wptr"
; PropertyBufferSize : DWORD -> "wptr"
; RequiredSize : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll" #cfunc global SetupDiGetDeviceRegistryPropertyW "SetupDiGetDeviceRegistryPropertyW" sptr, var, int, var, var, int, var ; res = SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyRegDataType : DWORD* optional, out -> "var" ; PropertyBuffer : BYTE* optional, out -> "var" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiGetDeviceRegistryPropertyW "SetupDiGetDeviceRegistryPropertyW" sptr, sptr, int, sptr, sptr, int, sptr ; res = SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, varptr(DeviceInfoData), Property, varptr(PropertyRegDataType), varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize)) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyRegDataType : DWORD* optional, out -> "sptr" ; PropertyBuffer : BYTE* optional, out -> "sptr" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL SetupDiGetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SETUP_DI_REGISTRY_PROPERTY Property, DWORD* PropertyRegDataType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupDiGetDeviceRegistryPropertyW "SetupDiGetDeviceRegistryPropertyW" intptr, var, int, var, var, int, var ; res = SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyRegDataType : DWORD* optional, out -> "var" ; PropertyBuffer : BYTE* optional, out -> "var" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiGetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SETUP_DI_REGISTRY_PROPERTY Property, DWORD* PropertyRegDataType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupDiGetDeviceRegistryPropertyW "SetupDiGetDeviceRegistryPropertyW" intptr, intptr, int, intptr, intptr, int, intptr ; res = SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, varptr(DeviceInfoData), Property, varptr(PropertyRegDataType), varptr(PropertyBuffer), PropertyBufferSize, varptr(RequiredSize)) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "intptr" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyRegDataType : DWORD* optional, out -> "intptr" ; PropertyBuffer : BYTE* optional, out -> "intptr" ; PropertyBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiGetDeviceRegistryPropertyW = setupapi.NewProc("SetupDiGetDeviceRegistryPropertyW")
)
// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA*), Property (SETUP_DI_REGISTRY_PROPERTY), PropertyRegDataType (DWORD* optional, out), PropertyBuffer (BYTE* optional, out), PropertyBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupDiGetDeviceRegistryPropertyW.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
uintptr(Property),
uintptr(PropertyRegDataType),
uintptr(PropertyBuffer),
uintptr(PropertyBufferSize),
uintptr(RequiredSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiGetDeviceRegistryPropertyW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA*
Property: DWORD; // SETUP_DI_REGISTRY_PROPERTY
PropertyRegDataType: Pointer; // DWORD* optional, out
PropertyBuffer: Pointer; // BYTE* optional, out
PropertyBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiGetDeviceRegistryPropertyW';result := DllCall("SETUPAPI\SetupDiGetDeviceRegistryPropertyW"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA*
, "UInt", Property ; SETUP_DI_REGISTRY_PROPERTY
, "Ptr", PropertyRegDataType ; DWORD* optional, out
, "Ptr", PropertyBuffer ; BYTE* optional, out
, "UInt", PropertyBufferSize ; DWORD
, "Ptr", RequiredSize ; DWORD* optional, out
, "Int") ; return: BOOL●SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupDiGetDeviceRegistryPropertyW(int, void*, dword, void*, void*, dword, void*)")
# 呼び出し: SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* -> "void*"
# Property : SETUP_DI_REGISTRY_PROPERTY -> "dword"
# PropertyRegDataType : DWORD* optional, out -> "void*"
# PropertyBuffer : BYTE* optional, out -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupDiGetDeviceRegistryPropertyW(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: [*c]SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
Property: u32, // SETUP_DI_REGISTRY_PROPERTY
PropertyRegDataType: [*c]u32, // DWORD* optional, out
PropertyBuffer: [*c]u8, // BYTE* optional, out
PropertyBufferSize: u32, // DWORD
RequiredSize: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupDiGetDeviceRegistryPropertyW(
DeviceInfoSet: int, # HDEVINFO
DeviceInfoData: ptr SP_DEVINFO_DATA, # SP_DEVINFO_DATA*
Property: uint32, # SETUP_DI_REGISTRY_PROPERTY
PropertyRegDataType: ptr uint32, # DWORD* optional, out
PropertyBuffer: ptr uint8, # BYTE* optional, out
PropertyBufferSize: uint32, # DWORD
RequiredSize: ptr uint32 # DWORD* optional, out
): int32 {.importc: "SetupDiGetDeviceRegistryPropertyW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
int SetupDiGetDeviceRegistryPropertyW(
ptrdiff_t DeviceInfoSet, // HDEVINFO
SP_DEVINFO_DATA* DeviceInfoData, // SP_DEVINFO_DATA*
uint Property, // SETUP_DI_REGISTRY_PROPERTY
uint* PropertyRegDataType, // DWORD* optional, out
ubyte* PropertyBuffer, // BYTE* optional, out
uint PropertyBufferSize, // DWORD
uint* RequiredSize // DWORD* optional, out
);ccall((:SetupDiGetDeviceRegistryPropertyW, "SETUPAPI.dll"), stdcall, Int32,
(Int, Ptr{SP_DEVINFO_DATA}, UInt32, Ptr{UInt32}, Ptr{UInt8}, UInt32, Ptr{UInt32}),
DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInfoData : SP_DEVINFO_DATA* -> Ptr{SP_DEVINFO_DATA}
# Property : SETUP_DI_REGISTRY_PROPERTY -> UInt32
# PropertyRegDataType : DWORD* optional, out -> Ptr{UInt32}
# PropertyBuffer : BYTE* optional, out -> Ptr{UInt8}
# PropertyBufferSize : DWORD -> UInt32
# RequiredSize : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiGetDeviceRegistryPropertyW(
intptr_t DeviceInfoSet,
void* DeviceInfoData,
uint32_t Property,
uint32_t* PropertyRegDataType,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize,
uint32_t* RequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
-- DeviceInfoSet : HDEVINFO
-- DeviceInfoData : SP_DEVINFO_DATA*
-- Property : SETUP_DI_REGISTRY_PROPERTY
-- PropertyRegDataType : DWORD* optional, out
-- PropertyBuffer : BYTE* optional, out
-- PropertyBufferSize : DWORD
-- RequiredSize : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiGetDeviceRegistryPropertyW = lib.func('__stdcall', 'SetupDiGetDeviceRegistryPropertyW', 'int32_t', ['intptr_t', 'void *', 'uint32_t', 'uint32_t *', 'uint8_t *', 'uint32_t', 'uint32_t *']);
// SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* -> 'void *'
// Property : SETUP_DI_REGISTRY_PROPERTY -> 'uint32_t'
// PropertyRegDataType : DWORD* optional, out -> 'uint32_t *'
// PropertyBuffer : BYTE* optional, out -> 'uint8_t *'
// PropertyBufferSize : DWORD -> 'uint32_t'
// RequiredSize : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupDiGetDeviceRegistryPropertyW: { parameters: ["isize", "pointer", "u32", "pointer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* -> "pointer"
// Property : SETUP_DI_REGISTRY_PROPERTY -> "u32"
// PropertyRegDataType : DWORD* optional, out -> "pointer"
// PropertyBuffer : BYTE* optional, out -> "pointer"
// PropertyBufferSize : DWORD -> "u32"
// RequiredSize : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiGetDeviceRegistryPropertyW(
intptr_t DeviceInfoSet,
void* DeviceInfoData,
uint32_t Property,
uint32_t* PropertyRegDataType,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize,
uint32_t* RequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupDiGetDeviceRegistryPropertyW(DeviceInfoSet, DeviceInfoData, Property, PropertyRegDataType, PropertyBuffer, PropertyBufferSize, RequiredSize);
// DeviceInfoSet : HDEVINFO
// DeviceInfoData : SP_DEVINFO_DATA*
// Property : SETUP_DI_REGISTRY_PROPERTY
// PropertyRegDataType : DWORD* optional, out
// PropertyBuffer : BYTE* optional, out
// PropertyBufferSize : DWORD
// RequiredSize : DWORD* optional, out
// 構造体/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, W32APIOptions.UNICODE_OPTIONS);
boolean SetupDiGetDeviceRegistryPropertyW(
long DeviceInfoSet, // HDEVINFO
Pointer DeviceInfoData, // SP_DEVINFO_DATA*
int Property, // SETUP_DI_REGISTRY_PROPERTY
IntByReference PropertyRegDataType, // DWORD* optional, out
byte[] PropertyBuffer, // BYTE* optional, out
int PropertyBufferSize, // DWORD
IntByReference RequiredSize // DWORD* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupDiGetDeviceRegistryPropertyW = SetupDiGetDeviceRegistryPropertyW(
DeviceInfoSet : LibC::SSizeT, # HDEVINFO
DeviceInfoData : SP_DEVINFO_DATA*, # SP_DEVINFO_DATA*
Property : UInt32, # SETUP_DI_REGISTRY_PROPERTY
PropertyRegDataType : UInt32*, # DWORD* optional, out
PropertyBuffer : UInt8*, # BYTE* optional, out
PropertyBufferSize : UInt32, # DWORD
RequiredSize : UInt32* # DWORD* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupDiGetDeviceRegistryPropertyWNative = Int32 Function(IntPtr, Pointer<Void>, Uint32, Pointer<Uint32>, Pointer<Uint8>, Uint32, Pointer<Uint32>);
typedef SetupDiGetDeviceRegistryPropertyWDart = int Function(int, Pointer<Void>, int, Pointer<Uint32>, Pointer<Uint8>, int, Pointer<Uint32>);
final SetupDiGetDeviceRegistryPropertyW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiGetDeviceRegistryPropertyWNative, SetupDiGetDeviceRegistryPropertyWDart>('SetupDiGetDeviceRegistryPropertyW');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* -> Pointer<Void>
// Property : SETUP_DI_REGISTRY_PROPERTY -> Uint32
// PropertyRegDataType : DWORD* optional, out -> Pointer<Uint32>
// PropertyBuffer : BYTE* optional, out -> Pointer<Uint8>
// PropertyBufferSize : DWORD -> Uint32
// RequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupDiGetDeviceRegistryPropertyW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA*
Property: DWORD; // SETUP_DI_REGISTRY_PROPERTY
PropertyRegDataType: Pointer; // DWORD* optional, out
PropertyBuffer: Pointer; // BYTE* optional, out
PropertyBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiGetDeviceRegistryPropertyW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiGetDeviceRegistryPropertyW"
c_SetupDiGetDeviceRegistryPropertyW :: CIntPtr -> Ptr () -> Word32 -> Ptr Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* -> Ptr ()
-- Property : SETUP_DI_REGISTRY_PROPERTY -> Word32
-- PropertyRegDataType : DWORD* optional, out -> Ptr Word32
-- PropertyBuffer : BYTE* optional, out -> Ptr Word8
-- PropertyBufferSize : DWORD -> Word32
-- RequiredSize : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupdigetdeviceregistrypropertyw =
foreign "SetupDiGetDeviceRegistryPropertyW"
(intptr_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* -> (ptr void) *)
(* Property : SETUP_DI_REGISTRY_PROPERTY -> uint32_t *)
(* PropertyRegDataType : DWORD* optional, out -> (ptr uint32_t) *)
(* PropertyBuffer : BYTE* optional, out -> (ptr uint8_t) *)
(* PropertyBufferSize : DWORD -> uint32_t *)
(* RequiredSize : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupDiGetDeviceRegistryPropertyW" setup-di-get-device-registry-property-w :convention :stdcall) :int32
(device-info-set :int64) ; HDEVINFO
(device-info-data :pointer) ; SP_DEVINFO_DATA*
(property :uint32) ; SETUP_DI_REGISTRY_PROPERTY
(property-reg-data-type :pointer) ; DWORD* optional, out
(property-buffer :pointer) ; BYTE* optional, out
(property-buffer-size :uint32) ; DWORD
(required-size :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupDiGetDeviceRegistryPropertyW = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiGetDeviceRegistryPropertyW(LPARAM DeviceInfoSet, LPVOID DeviceInfoData, DWORD Property, LPVOID PropertyRegDataType, LPVOID PropertyBuffer, DWORD PropertyBufferSize, LPVOID RequiredSize)');
# my $ret = $SetupDiGetDeviceRegistryPropertyW->Call($DeviceInfoSet, $DeviceInfoData, $Property, $PropertyRegDataType, $PropertyBuffer, $PropertyBufferSize, $RequiredSize);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* -> LPVOID
# Property : SETUP_DI_REGISTRY_PROPERTY -> DWORD
# PropertyRegDataType : DWORD* optional, out -> LPVOID
# PropertyBuffer : BYTE* optional, out -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f SetupDiGetDeviceRegistryPropertyA (ANSI版) — デバイスのPlug and Playレジストリプロパティを取得する。
- f SetupDiGetClassRegistryPropertyW — 指定したデバイスセットアップクラスのレジストリプロパティを取得する。
- f SetupDiSetClassRegistryPropertyW — デバイスセットアップクラスのレジストリプロパティを設定する。
- f SetupDiSetDeviceRegistryPropertyW — 指定デバイスのレジストリプロパティ値を設定する。