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

SetupDiCreateDevRegKeyA

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

シグネチャ

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

HKEY SetupDiCreateDevRegKeyA(
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData,
    DWORD Scope,
    DWORD HwProfile,
    DWORD KeyType,
    void* InfHandle,   // optional
    LPCSTR InfSectionName   // optional
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInfoDataSP_DEVINFO_DATA*in
ScopeDWORDin
HwProfileDWORDin
KeyTypeDWORDin
InfHandlevoid*inoptional
InfSectionNameLPCSTRinoptional

戻り値の型: HKEY

各言語での呼び出し定義

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

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

SetupDiCreateDevRegKeyA = ctypes.windll.setupapi.SetupDiCreateDevRegKeyA
SetupDiCreateDevRegKeyA.restype = ctypes.c_void_p
SetupDiCreateDevRegKeyA.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.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')
SetupDiCreateDevRegKeyA = Fiddle::Function.new(
  lib['SetupDiCreateDevRegKeyA'],
  [
    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 : LPCSTR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiCreateDevRegKeyA(
        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 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 SetupDiCreateDevRegKeyA(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, uint Scope, uint HwProfile, uint KeyType, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPStr)] string InfSectionName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiCreateDevRegKeyA' -Namespace Win32 -PassThru
# $api::SetupDiCreateDevRegKeyA(DeviceInfoSet, DeviceInfoData, Scope, HwProfile, KeyType, InfHandle, InfSectionName)
#uselib "SETUPAPI.dll"
#func global SetupDiCreateDevRegKeyA "SetupDiCreateDevRegKeyA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiCreateDevRegKeyA DeviceInfoSet, varptr(DeviceInfoData), Scope, HwProfile, KeyType, InfHandle, InfSectionName   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr"
; Scope : DWORD -> "sptr"
; HwProfile : DWORD -> "sptr"
; KeyType : DWORD -> "sptr"
; InfHandle : void* optional -> "sptr"
; InfSectionName : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiCreateDevRegKeyA "SetupDiCreateDevRegKeyA" sptr, var, int, int, int, sptr, str
; res = SetupDiCreateDevRegKeyA(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 : LPCSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HKEY SetupDiCreateDevRegKeyA(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, void* InfHandle, LPCSTR InfSectionName)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiCreateDevRegKeyA "SetupDiCreateDevRegKeyA" intptr, var, int, int, int, intptr, str
; res = SetupDiCreateDevRegKeyA(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 : LPCSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiCreateDevRegKeyA = setupapi.NewProc("SetupDiCreateDevRegKeyA")
)

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