ホーム › Devices.DeviceAndDriverInstallation › SetupDiCreateDeviceInterfaceRegKeyW
SetupDiCreateDeviceInterfaceRegKeyW
関数デバイスインターフェイス用のレジストリキーを作成する。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
HKEY SetupDiCreateDeviceInterfaceRegKeyW(
HDEVINFO DeviceInfoSet,
SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
DWORD Reserved, // optional
DWORD samDesired,
void* InfHandle, // optional
LPCWSTR InfSectionName // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| DeviceInfoSet | HDEVINFO | in |
| DeviceInterfaceData | SP_DEVICE_INTERFACE_DATA* | in |
| Reserved | DWORD | optional |
| samDesired | DWORD | in |
| InfHandle | void* | inoptional |
| InfSectionName | LPCWSTR | inoptional |
戻り値の型: HKEY
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
HKEY SetupDiCreateDeviceInterfaceRegKeyW(
HDEVINFO DeviceInfoSet,
SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
DWORD Reserved, // optional
DWORD samDesired,
void* InfHandle, // optional
LPCWSTR InfSectionName // optional
);[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SetupDiCreateDeviceInterfaceRegKeyW(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInterfaceData, // SP_DEVICE_INTERFACE_DATA*
uint Reserved, // DWORD optional
uint samDesired, // DWORD
IntPtr InfHandle, // void* optional
[MarshalAs(UnmanagedType.LPWStr)] string InfSectionName // LPCWSTR optional
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiCreateDeviceInterfaceRegKeyW(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInterfaceData As IntPtr, ' SP_DEVICE_INTERFACE_DATA*
Reserved As UInteger, ' DWORD optional
samDesired As UInteger, ' DWORD
InfHandle As IntPtr, ' void* optional
<MarshalAs(UnmanagedType.LPWStr)> InfSectionName As String ' LPCWSTR optional
) As IntPtr
End Function' DeviceInfoSet : HDEVINFO
' DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
' Reserved : DWORD optional
' samDesired : DWORD
' InfHandle : void* optional
' InfSectionName : LPCWSTR optional
Declare PtrSafe Function SetupDiCreateDeviceInterfaceRegKeyW Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInterfaceData As LongPtr, _
ByVal Reserved As Long, _
ByVal samDesired As Long, _
ByVal InfHandle As LongPtr, _
ByVal InfSectionName As LongPtr) As LongPtr
' 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
SetupDiCreateDeviceInterfaceRegKeyW = ctypes.windll.setupapi.SetupDiCreateDeviceInterfaceRegKeyW
SetupDiCreateDeviceInterfaceRegKeyW.restype = ctypes.c_void_p
SetupDiCreateDeviceInterfaceRegKeyW.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
wintypes.DWORD, # Reserved : DWORD optional
wintypes.DWORD, # samDesired : DWORD
ctypes.POINTER(None), # InfHandle : void* optional
wintypes.LPCWSTR, # InfSectionName : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiCreateDeviceInterfaceRegKeyW = Fiddle::Function.new(
lib['SetupDiCreateDeviceInterfaceRegKeyW'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
-Fiddle::TYPE_INT, # Reserved : DWORD optional
-Fiddle::TYPE_INT, # samDesired : DWORD
Fiddle::TYPE_VOIDP, # InfHandle : void* optional
Fiddle::TYPE_VOIDP, # InfSectionName : LPCWSTR optional
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupDiCreateDeviceInterfaceRegKeyW(
DeviceInfoSet: isize, // HDEVINFO
DeviceInterfaceData: *mut SP_DEVICE_INTERFACE_DATA, // SP_DEVICE_INTERFACE_DATA*
Reserved: u32, // DWORD optional
samDesired: u32, // DWORD
InfHandle: *mut (), // void* optional
InfSectionName: *const u16 // LPCWSTR optional
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr SetupDiCreateDeviceInterfaceRegKeyW(IntPtr DeviceInfoSet, IntPtr DeviceInterfaceData, uint Reserved, uint samDesired, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPWStr)] string InfSectionName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiCreateDeviceInterfaceRegKeyW' -Namespace Win32 -PassThru
# $api::SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName)#uselib "SETUPAPI.dll"
#func global SetupDiCreateDeviceInterfaceRegKeyW "SetupDiCreateDeviceInterfaceRegKeyW" wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiCreateDeviceInterfaceRegKeyW DeviceInfoSet, varptr(DeviceInterfaceData), Reserved, samDesired, InfHandle, InfSectionName ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "wptr"
; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "wptr"
; Reserved : DWORD optional -> "wptr"
; samDesired : DWORD -> "wptr"
; InfHandle : void* optional -> "wptr"
; InfSectionName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInterfaceRegKeyW "SetupDiCreateDeviceInterfaceRegKeyW" sptr, var, int, int, sptr, wstr ; res = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "var" ; Reserved : DWORD optional -> "int" ; samDesired : DWORD -> "int" ; InfHandle : void* optional -> "sptr" ; InfSectionName : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInterfaceRegKeyW "SetupDiCreateDeviceInterfaceRegKeyW" sptr, sptr, int, int, sptr, wstr ; res = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, varptr(DeviceInterfaceData), Reserved, samDesired, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "sptr" ; Reserved : DWORD optional -> "int" ; samDesired : DWORD -> "int" ; InfHandle : void* optional -> "sptr" ; InfSectionName : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HKEY SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData, DWORD Reserved, DWORD samDesired, void* InfHandle, LPCWSTR InfSectionName) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInterfaceRegKeyW "SetupDiCreateDeviceInterfaceRegKeyW" intptr, var, int, int, intptr, wstr ; res = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "var" ; Reserved : DWORD optional -> "int" ; samDesired : DWORD -> "int" ; InfHandle : void* optional -> "intptr" ; InfSectionName : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HKEY SetupDiCreateDeviceInterfaceRegKeyW(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData, DWORD Reserved, DWORD samDesired, void* InfHandle, LPCWSTR InfSectionName) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDeviceInterfaceRegKeyW "SetupDiCreateDeviceInterfaceRegKeyW" intptr, intptr, int, int, intptr, wstr ; res = SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, varptr(DeviceInterfaceData), Reserved, samDesired, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "intptr" ; Reserved : DWORD optional -> "int" ; samDesired : DWORD -> "int" ; InfHandle : void* optional -> "intptr" ; InfSectionName : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiCreateDeviceInterfaceRegKeyW = setupapi.NewProc("SetupDiCreateDeviceInterfaceRegKeyW")
)
// DeviceInfoSet (HDEVINFO), DeviceInterfaceData (SP_DEVICE_INTERFACE_DATA*), Reserved (DWORD optional), samDesired (DWORD), InfHandle (void* optional), InfSectionName (LPCWSTR optional)
r1, _, err := procSetupDiCreateDeviceInterfaceRegKeyW.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInterfaceData),
uintptr(Reserved),
uintptr(samDesired),
uintptr(InfHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(InfSectionName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HKEYfunction SetupDiCreateDeviceInterfaceRegKeyW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInterfaceData: Pointer; // SP_DEVICE_INTERFACE_DATA*
Reserved: DWORD; // DWORD optional
samDesired: DWORD; // DWORD
InfHandle: Pointer; // void* optional
InfSectionName: PWideChar // LPCWSTR optional
): THandle; stdcall;
external 'SETUPAPI.dll' name 'SetupDiCreateDeviceInterfaceRegKeyW';result := DllCall("SETUPAPI\SetupDiCreateDeviceInterfaceRegKeyW"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInterfaceData ; SP_DEVICE_INTERFACE_DATA*
, "UInt", Reserved ; DWORD optional
, "UInt", samDesired ; DWORD
, "Ptr", InfHandle ; void* optional
, "WStr", InfSectionName ; LPCWSTR optional
, "Ptr") ; return: HKEY●SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName) = DLL("SETUPAPI.dll", "void* SetupDiCreateDeviceInterfaceRegKeyW(int, void*, dword, dword, void*, char*)")
# 呼び出し: SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "void*"
# Reserved : DWORD optional -> "dword"
# samDesired : DWORD -> "dword"
# InfHandle : void* optional -> "void*"
# InfSectionName : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。