ホーム › Devices.DeviceAndDriverInstallation › SetupDiOpenDevRegKey
SetupDiOpenDevRegKey
関数デバイス用のレジストリキーをスコープ指定で開く。
シグネチャ
// SETUPAPI.dll
#include <windows.h>
HKEY SetupDiOpenDevRegKey(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
DWORD Scope,
DWORD HwProfile,
DWORD KeyType,
DWORD samDesired
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| DeviceInfoSet | HDEVINFO | in |
| DeviceInfoData | SP_DEVINFO_DATA* | in |
| Scope | DWORD | in |
| HwProfile | DWORD | in |
| KeyType | DWORD | in |
| samDesired | DWORD | in |
戻り値の型: HKEY
各言語での呼び出し定義
// SETUPAPI.dll
#include <windows.h>
HKEY SetupDiOpenDevRegKey(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
DWORD Scope,
DWORD HwProfile,
DWORD KeyType,
DWORD samDesired
);[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr SetupDiOpenDevRegKey(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData, // SP_DEVINFO_DATA*
uint Scope, // DWORD
uint HwProfile, // DWORD
uint KeyType, // DWORD
uint samDesired // DWORD
);<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiOpenDevRegKey(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr, ' SP_DEVINFO_DATA*
Scope As UInteger, ' DWORD
HwProfile As UInteger, ' DWORD
KeyType As UInteger, ' DWORD
samDesired As UInteger ' DWORD
) As IntPtr
End Function' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
' Scope : DWORD
' HwProfile : DWORD
' KeyType : DWORD
' samDesired : DWORD
Declare PtrSafe Function SetupDiOpenDevRegKey Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr, _
ByVal Scope As Long, _
ByVal HwProfile As Long, _
ByVal KeyType As Long, _
ByVal samDesired As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiOpenDevRegKey = ctypes.windll.setupapi.SetupDiOpenDevRegKey
SetupDiOpenDevRegKey.restype = ctypes.c_void_p
SetupDiOpenDevRegKey.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
wintypes.DWORD, # samDesired : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiOpenDevRegKey = Fiddle::Function.new(
lib['SetupDiOpenDevRegKey'],
[
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_INT, # samDesired : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "setupapi")]
extern "system" {
fn SetupDiOpenDevRegKey(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA, // SP_DEVINFO_DATA*
Scope: u32, // DWORD
HwProfile: u32, // DWORD
KeyType: u32, // DWORD
samDesired: u32 // DWORD
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SETUPAPI.dll", SetLastError = true)]
public static extern IntPtr SetupDiOpenDevRegKey(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, uint Scope, uint HwProfile, uint KeyType, uint samDesired);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiOpenDevRegKey' -Namespace Win32 -PassThru
# $api::SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, samDesired)#uselib "SETUPAPI.dll"
#func global SetupDiOpenDevRegKey "SetupDiOpenDevRegKey" sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiOpenDevRegKey DeviceInfoSet, varptr(DeviceInfoData), Scope, HwProfile, KeyType, samDesired ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr"
; Scope : DWORD -> "sptr"
; HwProfile : DWORD -> "sptr"
; KeyType : DWORD -> "sptr"
; samDesired : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDevRegKey "SetupDiOpenDevRegKey" sptr, var, int, int, int, int ; res = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, samDesired) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : DWORD -> "int" ; samDesired : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDevRegKey "SetupDiOpenDevRegKey" sptr, sptr, int, int, int, int ; res = SetupDiOpenDevRegKey(DeviceInfoSet, varptr(DeviceInfoData), Scope, HwProfile, KeyType, samDesired) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : DWORD -> "int" ; samDesired : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HKEY SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, DWORD samDesired) #uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDevRegKey "SetupDiOpenDevRegKey" intptr, var, int, int, int, int ; res = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, samDesired) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : DWORD -> "int" ; samDesired : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HKEY SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, DWORD samDesired) #uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDevRegKey "SetupDiOpenDevRegKey" intptr, intptr, int, int, int, int ; res = SetupDiOpenDevRegKey(DeviceInfoSet, varptr(DeviceInfoData), Scope, HwProfile, KeyType, samDesired) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "intptr" ; Scope : DWORD -> "int" ; HwProfile : DWORD -> "int" ; KeyType : DWORD -> "int" ; samDesired : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiOpenDevRegKey = setupapi.NewProc("SetupDiOpenDevRegKey")
)
// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA*), Scope (DWORD), HwProfile (DWORD), KeyType (DWORD), samDesired (DWORD)
r1, _, err := procSetupDiOpenDevRegKey.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
uintptr(Scope),
uintptr(HwProfile),
uintptr(KeyType),
uintptr(samDesired),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HKEYfunction SetupDiOpenDevRegKey(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA*
Scope: DWORD; // DWORD
HwProfile: DWORD; // DWORD
KeyType: DWORD; // DWORD
samDesired: DWORD // DWORD
): THandle; stdcall;
external 'SETUPAPI.dll' name 'SetupDiOpenDevRegKey';result := DllCall("SETUPAPI\SetupDiOpenDevRegKey"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA*
, "UInt", Scope ; DWORD
, "UInt", HwProfile ; DWORD
, "UInt", KeyType ; DWORD
, "UInt", samDesired ; DWORD
, "Ptr") ; return: HKEY●SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, samDesired) = DLL("SETUPAPI.dll", "void* SetupDiOpenDevRegKey(int, void*, dword, dword, dword, dword)")
# 呼び出し: SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, samDesired)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* -> "void*"
# Scope : DWORD -> "dword"
# HwProfile : DWORD -> "dword"
# KeyType : DWORD -> "dword"
# samDesired : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。