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

SetupDiCreateDeviceInterfaceRegKeyW

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

シグネチャ

// 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
);

パラメーター

名前方向説明
DeviceInfoSetHDEVINFOin対象のデバイス情報セットを指すハンドル。
DeviceInterfaceDataSP_DEVICE_INTERFACE_DATA*inレジストリキーを作成する対象デバイスインターフェイスの構造体。
ReservedDWORDoptional予約済み。0を指定する。
samDesiredDWORDin要求するレジストリアクセス権。KEY_WRITE等を指定する。
InfHandlevoid*inoptional適用するINFのハンドル。InfSectionName併用時に指定し、不要ならNULL。
InfSectionNameLPCWSTRinoptional実行するINFセクション名(Unicode)。不要ならNULLを指定する。

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // HKEY
function 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 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn SetupDiCreateDeviceInterfaceRegKeyW(
    DeviceInfoSet: isize, // HDEVINFO
    DeviceInterfaceData: [*c]SP_DEVICE_INTERFACE_DATA, // SP_DEVICE_INTERFACE_DATA*
    Reserved: u32, // DWORD optional
    samDesired: u32, // DWORD
    InfHandle: ?*anyopaque, // void* optional
    InfSectionName: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupDiCreateDeviceInterfaceRegKeyW(
    DeviceInfoSet: int,  # HDEVINFO
    DeviceInterfaceData: ptr SP_DEVICE_INTERFACE_DATA,  # SP_DEVICE_INTERFACE_DATA*
    Reserved: uint32,  # DWORD optional
    samDesired: uint32,  # DWORD
    InfHandle: pointer,  # void* optional
    InfSectionName: WideCString  # LPCWSTR optional
): pointer {.importc: "SetupDiCreateDeviceInterfaceRegKeyW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
void* SetupDiCreateDeviceInterfaceRegKeyW(
    ptrdiff_t DeviceInfoSet,   // HDEVINFO
    SP_DEVICE_INTERFACE_DATA* DeviceInterfaceData,   // SP_DEVICE_INTERFACE_DATA*
    uint Reserved,   // DWORD optional
    uint samDesired,   // DWORD
    void* InfHandle,   // void* optional
    const(wchar)* InfSectionName   // LPCWSTR optional
);
ccall((:SetupDiCreateDeviceInterfaceRegKeyW, "SETUPAPI.dll"), stdcall, Ptr{Cvoid},
      (Int, Ptr{SP_DEVICE_INTERFACE_DATA}, UInt32, UInt32, Ptr{Cvoid}, Cwstring),
      DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> Ptr{SP_DEVICE_INTERFACE_DATA}
# Reserved : DWORD optional -> UInt32
# samDesired : DWORD -> UInt32
# InfHandle : void* optional -> Ptr{Cvoid}
# InfSectionName : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
void* SetupDiCreateDeviceInterfaceRegKeyW(
    intptr_t DeviceInfoSet,
    void* DeviceInterfaceData,
    uint32_t Reserved,
    uint32_t samDesired,
    void* InfHandle,
    const uint16_t* InfSectionName);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName)
-- DeviceInfoSet : HDEVINFO
-- DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
-- Reserved : DWORD optional
-- samDesired : DWORD
-- InfHandle : void* optional
-- InfSectionName : LPCWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiCreateDeviceInterfaceRegKeyW = lib.func('__stdcall', 'SetupDiCreateDeviceInterfaceRegKeyW', 'void *', ['intptr_t', 'void *', 'uint32_t', 'uint32_t', 'void *', 'str16']);
// SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> 'void *'
// Reserved : DWORD optional -> 'uint32_t'
// samDesired : DWORD -> 'uint32_t'
// InfHandle : void* optional -> 'void *'
// InfSectionName : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiCreateDeviceInterfaceRegKeyW: { parameters: ["isize", "pointer", "u32", "u32", "pointer", "buffer"], result: "pointer" },
});
// lib.symbols.SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> "pointer"
// Reserved : DWORD optional -> "u32"
// samDesired : DWORD -> "u32"
// InfHandle : void* optional -> "pointer"
// InfSectionName : LPCWSTR optional -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* SetupDiCreateDeviceInterfaceRegKeyW(
    intptr_t DeviceInfoSet,
    void* DeviceInterfaceData,
    uint32_t Reserved,
    uint32_t samDesired,
    void* InfHandle,
    const uint16_t* InfSectionName);
C, "SETUPAPI.dll");
// $ffi->SetupDiCreateDeviceInterfaceRegKeyW(DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired, InfHandle, InfSectionName);
// DeviceInfoSet : HDEVINFO
// DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*
// Reserved : DWORD optional
// samDesired : DWORD
// InfHandle : void* optional
// InfSectionName : LPCWSTR optional
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Setupapi extends StdCallLibrary {
    Setupapi INSTANCE = Native.load("setupapi", Setupapi.class, W32APIOptions.UNICODE_OPTIONS);
    Pointer SetupDiCreateDeviceInterfaceRegKeyW(
        long DeviceInfoSet,   // HDEVINFO
        Pointer DeviceInterfaceData,   // SP_DEVICE_INTERFACE_DATA*
        int Reserved,   // DWORD optional
        int samDesired,   // DWORD
        Pointer InfHandle,   // void* optional
        WString InfSectionName   // LPCWSTR optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiCreateDeviceInterfaceRegKeyW = SetupDiCreateDeviceInterfaceRegKeyW(
    DeviceInfoSet : LibC::SSizeT,   # HDEVINFO
    DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA*,   # SP_DEVICE_INTERFACE_DATA*
    Reserved : UInt32,   # DWORD optional
    samDesired : UInt32,   # DWORD
    InfHandle : Void*,   # void* optional
    InfSectionName : UInt16*   # LPCWSTR optional
  ) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupDiCreateDeviceInterfaceRegKeyWNative = Pointer<Void> Function(IntPtr, Pointer<Void>, Uint32, Uint32, Pointer<Void>, Pointer<Utf16>);
typedef SetupDiCreateDeviceInterfaceRegKeyWDart = Pointer<Void> Function(int, Pointer<Void>, int, int, Pointer<Void>, Pointer<Utf16>);
final SetupDiCreateDeviceInterfaceRegKeyW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiCreateDeviceInterfaceRegKeyWNative, SetupDiCreateDeviceInterfaceRegKeyWDart>('SetupDiCreateDeviceInterfaceRegKeyW');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> Pointer<Void>
// Reserved : DWORD optional -> Uint32
// samDesired : DWORD -> Uint32
// InfHandle : void* optional -> Pointer<Void>
// InfSectionName : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function 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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiCreateDeviceInterfaceRegKeyW"
  c_SetupDiCreateDeviceInterfaceRegKeyW :: CIntPtr -> Ptr () -> Word32 -> Word32 -> Ptr () -> CWString -> IO (Ptr ())
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> Ptr ()
-- Reserved : DWORD optional -> Word32
-- samDesired : DWORD -> Word32
-- InfHandle : void* optional -> Ptr ()
-- InfSectionName : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdicreatedeviceinterfaceregkeyw =
  foreign "SetupDiCreateDeviceInterfaceRegKeyW"
    (intptr_t @-> (ptr void) @-> uint32_t @-> uint32_t @-> (ptr void) @-> (ptr uint16_t) @-> returning (ptr void))
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> (ptr void) *)
(* Reserved : DWORD optional -> uint32_t *)
(* samDesired : DWORD -> uint32_t *)
(* InfHandle : void* optional -> (ptr void) *)
(* InfSectionName : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupDiCreateDeviceInterfaceRegKeyW" setup-di-create-device-interface-reg-key-w :convention :stdcall) :pointer
  (device-info-set :int64)   ; HDEVINFO
  (device-interface-data :pointer)   ; SP_DEVICE_INTERFACE_DATA*
  (reserved :uint32)   ; DWORD optional
  (sam-desired :uint32)   ; DWORD
  (inf-handle :pointer)   ; void* optional
  (inf-section-name (:string :encoding :utf-16le)))   ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiCreateDeviceInterfaceRegKeyW = Win32::API::More->new('SETUPAPI',
    'HANDLE SetupDiCreateDeviceInterfaceRegKeyW(LPARAM DeviceInfoSet, LPVOID DeviceInterfaceData, DWORD Reserved, DWORD samDesired, LPVOID InfHandle, LPCWSTR InfSectionName)');
# my $ret = $SetupDiCreateDeviceInterfaceRegKeyW->Call($DeviceInfoSet, $DeviceInterfaceData, $Reserved, $samDesired, $InfHandle, $InfSectionName);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInterfaceData : SP_DEVICE_INTERFACE_DATA* -> LPVOID
# Reserved : DWORD optional -> DWORD
# samDesired : DWORD -> DWORD
# InfHandle : void* optional -> LPVOID
# InfSectionName : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型