Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupDiCreateDeviceInterfaceRegKeyA

SetupDiCreateDeviceInterfaceRegKeyA

関数
デバイスインターフェイス用のレジストリキーを作成する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

HKEY SetupDiCreateDeviceInterfaceRegKeyA(
    HDEVINFO DeviceInfoSet,
    SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
    DWORD Reserved,   // optional
    DWORD samDesired,
    void* InfHandle,   // optional
    LPCSTR InfSectionName   // optional
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInterfaceDataSP_DEVICE_INTERFACE_DATA*in
ReservedDWORDoptional
samDesiredDWORDin
InfHandlevoid*inoptional
InfSectionNameLPCSTRinoptional

戻り値の型: HKEY

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

HKEY SetupDiCreateDeviceInterfaceRegKeyA(
    HDEVINFO DeviceInfoSet,
    SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,
    DWORD Reserved,   // optional
    DWORD samDesired,
    void* InfHandle,   // optional
    LPCSTR InfSectionName   // optional
);
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SetupDiCreateDeviceInterfaceRegKeyA(
    IntPtr DeviceInfoSet,   // HDEVINFO
    IntPtr DeviceInterfaceData,   // SP_DEVICE_INTERFACE_DATA*
    uint Reserved,   // DWORD optional
    uint samDesired,   // DWORD
    IntPtr InfHandle,   // void* optional
    [MarshalAs(UnmanagedType.LPStr)] string InfSectionName   // LPCSTR optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiCreateDeviceInterfaceRegKeyA(
    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.LPStr)> InfSectionName As String   ' LPCSTR optional
) As IntPtr
End Function
' DeviceInfoSet : HDEVINFO
' DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
' Reserved : DWORD optional
' samDesired : DWORD
' InfHandle : void* optional
' InfSectionName : LPCSTR optional
Declare PtrSafe Function SetupDiCreateDeviceInterfaceRegKeyA 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 String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiCreateDeviceInterfaceRegKeyA = ctypes.windll.setupapi.SetupDiCreateDeviceInterfaceRegKeyA
SetupDiCreateDeviceInterfaceRegKeyA.restype = ctypes.c_void_p
SetupDiCreateDeviceInterfaceRegKeyA.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.LPCSTR,  # InfSectionName : LPCSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiCreateDeviceInterfaceRegKeyA = Fiddle::Function.new(
  lib['SetupDiCreateDeviceInterfaceRegKeyA'],
  [
    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 : LPCSTR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiCreateDeviceInterfaceRegKeyA(
        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 u8  // LPCSTR optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr SetupDiCreateDeviceInterfaceRegKeyA(IntPtr DeviceInfoSet, IntPtr DeviceInterfaceData, uint Reserved, uint samDesired, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPStr)] string InfSectionName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiCreateDeviceInterfaceRegKeyA' -Namespace Win32 -PassThru
# $api::SetupDiCreateDeviceInterfaceRegKeyA(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName)
#uselib "SETUPAPI.dll"
#func global SetupDiCreateDeviceInterfaceRegKeyA "SetupDiCreateDeviceInterfaceRegKeyA" sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiCreateDeviceInterfaceRegKeyA DeviceInfoSet, varptr(DeviceInterfaceData), Reserved, samDesired, InfHandle, InfSectionName   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "sptr"
; Reserved : DWORD optional -> "sptr"
; samDesired : DWORD -> "sptr"
; InfHandle : void* optional -> "sptr"
; InfSectionName : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiCreateDeviceInterfaceRegKeyA "SetupDiCreateDeviceInterfaceRegKeyA" sptr, var, int, int, sptr, str
; res = SetupDiCreateDeviceInterfaceRegKeyA(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 : LPCSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HKEY SetupDiCreateDeviceInterfaceRegKeyA(HDEVINFO DeviceInfoSet, SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData, DWORD Reserved, DWORD samDesired, void* InfHandle, LPCSTR InfSectionName)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiCreateDeviceInterfaceRegKeyA "SetupDiCreateDeviceInterfaceRegKeyA" intptr, var, int, int, intptr, str
; res = SetupDiCreateDeviceInterfaceRegKeyA(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 : LPCSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiCreateDeviceInterfaceRegKeyA = setupapi.NewProc("SetupDiCreateDeviceInterfaceRegKeyA")
)

// DeviceInfoSet (HDEVINFO), DeviceInterfaceData (SP_DEVICE_INTERFACE_DATA*), Reserved (DWORD optional), samDesired (DWORD), InfHandle (void* optional), InfSectionName (LPCSTR optional)
r1, _, err := procSetupDiCreateDeviceInterfaceRegKeyA.Call(
	uintptr(DeviceInfoSet),
	uintptr(DeviceInterfaceData),
	uintptr(Reserved),
	uintptr(samDesired),
	uintptr(InfHandle),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(InfSectionName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HKEY
function SetupDiCreateDeviceInterfaceRegKeyA(
  DeviceInfoSet: NativeInt;   // HDEVINFO
  DeviceInterfaceData: Pointer;   // SP_DEVICE_INTERFACE_DATA*
  Reserved: DWORD;   // DWORD optional
  samDesired: DWORD;   // DWORD
  InfHandle: Pointer;   // void* optional
  InfSectionName: PAnsiChar   // LPCSTR optional
): THandle; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiCreateDeviceInterfaceRegKeyA';
result := DllCall("SETUPAPI\SetupDiCreateDeviceInterfaceRegKeyA"
    , "Ptr", DeviceInfoSet   ; HDEVINFO
    , "Ptr", DeviceInterfaceData   ; SP_DEVICE_INTERFACE_DATA*
    , "UInt", Reserved   ; DWORD optional
    , "UInt", samDesired   ; DWORD
    , "Ptr", InfHandle   ; void* optional
    , "AStr", InfSectionName   ; LPCSTR optional
    , "Ptr")   ; return: HKEY
●SetupDiCreateDeviceInterfaceRegKeyA(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName) = DLL("SETUPAPI.dll", "void* SetupDiCreateDeviceInterfaceRegKeyA(int, void*, dword, dword, void*, char*)")
# 呼び出し: SetupDiCreateDeviceInterfaceRegKeyA(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 : LPCSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。