ホーム › Devices.DeviceAndDriverInstallation › SetupDiCreateDevRegKeyW
SetupDiCreateDevRegKeyW
関数デバイス用のレジストリキーをスコープ指定で作成する。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
HKEY SetupDiCreateDevRegKeyW(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
DWORD Scope,
DWORD HwProfile,
DWORD KeyType,
void* InfHandle, // optional
LPCWSTR InfSectionName // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| DeviceInfoSet | HDEVINFO | in |
| DeviceInfoData | SP_DEVINFO_DATA* | in |
| Scope | DWORD | in |
| HwProfile | DWORD | in |
| KeyType | DWORD | in |
| InfHandle | void* | inoptional |
| InfSectionName | LPCWSTR | inoptional |
戻り値の型: HKEY
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
HKEY SetupDiCreateDevRegKeyW(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
DWORD Scope,
DWORD HwProfile,
DWORD KeyType,
void* InfHandle, // optional
LPCWSTR InfSectionName // optional
);[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SetupDiCreateDevRegKeyW(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData, // SP_DEVINFO_DATA*
uint Scope, // DWORD
uint HwProfile, // DWORD
uint KeyType, // 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 SetupDiCreateDevRegKeyW(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr, ' SP_DEVINFO_DATA*
Scope As UInteger, ' DWORD
HwProfile As UInteger, ' DWORD
KeyType As UInteger, ' DWORD
InfHandle As IntPtr, ' void* optional
<MarshalAs(UnmanagedType.LPWStr)> InfSectionName As String ' LPCWSTR optional
) As IntPtr
End Function' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
' Scope : DWORD
' HwProfile : DWORD
' KeyType : DWORD
' InfHandle : void* optional
' InfSectionName : LPCWSTR optional
Declare PtrSafe Function SetupDiCreateDevRegKeyW Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr, _
ByVal Scope As Long, _
ByVal HwProfile As Long, _
ByVal KeyType 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
SetupDiCreateDevRegKeyW = ctypes.windll.setupapi.SetupDiCreateDevRegKeyW
SetupDiCreateDevRegKeyW.restype = ctypes.c_void_p
SetupDiCreateDevRegKeyW.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA*
wintypes.DWORD, # Scope : DWORD
wintypes.DWORD, # HwProfile : DWORD
wintypes.DWORD, # KeyType : 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')
SetupDiCreateDevRegKeyW = Fiddle::Function.new(
lib['SetupDiCreateDevRegKeyW'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA*
-Fiddle::TYPE_INT, # Scope : DWORD
-Fiddle::TYPE_INT, # HwProfile : DWORD
-Fiddle::TYPE_INT, # KeyType : 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 SetupDiCreateDevRegKeyW(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
Scope: u32, // DWORD
HwProfile: u32, // DWORD
KeyType: 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 SetupDiCreateDevRegKeyW(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, uint Scope, uint HwProfile, uint KeyType, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPWStr)] string InfSectionName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiCreateDevRegKeyW' -Namespace Win32 -PassThru
# $api::SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, InfHandle, InfSectionName)#uselib "SETUPAPI.dll"
#func global SetupDiCreateDevRegKeyW "SetupDiCreateDevRegKeyW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiCreateDevRegKeyW DeviceInfoSet, varptr(DeviceInfoData), Scope, HwProfile, KeyType, InfHandle, InfSectionName ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "wptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "wptr"
; Scope : DWORD -> "wptr"
; HwProfile : DWORD -> "wptr"
; KeyType : DWORD -> "wptr"
; InfHandle : void* optional -> "wptr"
; InfSectionName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDevRegKeyW "SetupDiCreateDevRegKeyW" sptr, var, int, int, int, sptr, wstr ; res = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : DWORD -> "int" ; InfHandle : void* optional -> "sptr" ; InfSectionName : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDevRegKeyW "SetupDiCreateDevRegKeyW" sptr, sptr, int, int, int, sptr, wstr ; res = SetupDiCreateDevRegKeyW(DeviceInfoSet, varptr(DeviceInfoData), Scope, HwProfile, KeyType, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : DWORD -> "int" ; InfHandle : void* optional -> "sptr" ; InfSectionName : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HKEY SetupDiCreateDevRegKeyW(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, void* InfHandle, LPCWSTR InfSectionName) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDevRegKeyW "SetupDiCreateDevRegKeyW" intptr, var, int, int, int, intptr, wstr ; res = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : DWORD -> "int" ; InfHandle : void* optional -> "intptr" ; InfSectionName : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HKEY SetupDiCreateDevRegKeyW(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, void* InfHandle, LPCWSTR InfSectionName) #uselib "SETUPAPI.dll" #cfunc global SetupDiCreateDevRegKeyW "SetupDiCreateDevRegKeyW" intptr, intptr, int, int, int, intptr, wstr ; res = SetupDiCreateDevRegKeyW(DeviceInfoSet, varptr(DeviceInfoData), Scope, HwProfile, KeyType, InfHandle, InfSectionName) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "intptr" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : 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")
procSetupDiCreateDevRegKeyW = setupapi.NewProc("SetupDiCreateDevRegKeyW")
)
// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA*), Scope (DWORD), HwProfile (DWORD), KeyType (DWORD), InfHandle (void* optional), InfSectionName (LPCWSTR optional)
r1, _, err := procSetupDiCreateDevRegKeyW.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
uintptr(Scope),
uintptr(HwProfile),
uintptr(KeyType),
uintptr(InfHandle),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(InfSectionName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HKEYfunction SetupDiCreateDevRegKeyW(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA*
Scope: DWORD; // DWORD
HwProfile: DWORD; // DWORD
KeyType: DWORD; // DWORD
InfHandle: Pointer; // void* optional
InfSectionName: PWideChar // LPCWSTR optional
): THandle; stdcall;
external 'SETUPAPI.dll' name 'SetupDiCreateDevRegKeyW';result := DllCall("SETUPAPI\SetupDiCreateDevRegKeyW"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA*
, "UInt", Scope ; DWORD
, "UInt", HwProfile ; DWORD
, "UInt", KeyType ; DWORD
, "Ptr", InfHandle ; void* optional
, "WStr", InfSectionName ; LPCWSTR optional
, "Ptr") ; return: HKEY●SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, InfHandle, InfSectionName) = DLL("SETUPAPI.dll", "void* SetupDiCreateDevRegKeyW(int, void*, dword, dword, dword, void*, char*)")
# 呼び出し: SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, InfHandle, InfSectionName)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* -> "void*"
# Scope : DWORD -> "dword"
# HwProfile : DWORD -> "dword"
# KeyType : DWORD -> "dword"
# InfHandle : void* optional -> "void*"
# InfSectionName : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。