ホーム › Devices.DeviceAndDriverInstallation › SetupDiSetDeviceRegistryPropertyA
SetupDiSetDeviceRegistryPropertyA
関数指定デバイスのレジストリプロパティ値を設定する。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiSetDeviceRegistryPropertyA(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
SETUP_DI_REGISTRY_PROPERTY Property,
const BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize
);パラメーター
戻り値の型: BOOL
公式ドキュメント
SetupDiSetDeviceRegistryProperty 関数は、デバイスのプラグ アンド プレイ デバイス プロパティを設定します。(ANSI)
戻り値
関数が成功した場合は TRUE を返します。それ以外の場合は FALSE を返し、記録されたエラーは GetLastError を呼び出して取得できます。
解説(Remarks)
この関数の呼び出し元は、Administrators グループのメンバーである必要があります。
クラス名プロパティは、対応するクラス GUID に基づいており、その GUID が変更されると自動的に更新されるため、設定できません。ClassGUID プロパティが変更されると、SetupDiSetDeviceRegistryProperty はそのデバイスに関連付けられたソフトウェア キーを自動的にクリーンアップします。
メモ
setupapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして SetupDiSetDeviceRegistryProperty を定義しています。エンコードに依存しないエイリアスの使用と、エンコードに依存するコードを混在させると、不一致が生じ、コンパイル エラーまたは実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則 を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiSetDeviceRegistryPropertyA(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData,
SETUP_DI_REGISTRY_PROPERTY Property,
const BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiSetDeviceRegistryPropertyA(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData, // SP_DEVINFO_DATA* in/out
uint Property, // SETUP_DI_REGISTRY_PROPERTY
IntPtr PropertyBuffer, // BYTE* optional
uint PropertyBufferSize // DWORD
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiSetDeviceRegistryPropertyA(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr, ' SP_DEVINFO_DATA* in/out
[Property] As UInteger, ' SETUP_DI_REGISTRY_PROPERTY
PropertyBuffer As IntPtr, ' BYTE* optional
PropertyBufferSize As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA* in/out
' Property : SETUP_DI_REGISTRY_PROPERTY
' PropertyBuffer : BYTE* optional
' PropertyBufferSize : DWORD
Declare PtrSafe Function SetupDiSetDeviceRegistryPropertyA Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr, _
ByVal Property As Long, _
ByVal PropertyBuffer As LongPtr, _
ByVal PropertyBufferSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiSetDeviceRegistryPropertyA = ctypes.windll.setupapi.SetupDiSetDeviceRegistryPropertyA
SetupDiSetDeviceRegistryPropertyA.restype = wintypes.BOOL
SetupDiSetDeviceRegistryPropertyA.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA* in/out
wintypes.DWORD, # Property : SETUP_DI_REGISTRY_PROPERTY
ctypes.POINTER(ctypes.c_ubyte), # PropertyBuffer : BYTE* optional
wintypes.DWORD, # PropertyBufferSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiSetDeviceRegistryPropertyA = Fiddle::Function.new(
lib['SetupDiSetDeviceRegistryPropertyA'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA* in/out
-Fiddle::TYPE_INT, # Property : SETUP_DI_REGISTRY_PROPERTY
Fiddle::TYPE_VOIDP, # PropertyBuffer : BYTE* optional
-Fiddle::TYPE_INT, # PropertyBufferSize : DWORD
],
Fiddle::TYPE_INT)#[link(name = "setupapi")]
extern "system" {
fn SetupDiSetDeviceRegistryPropertyA(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA, // SP_DEVINFO_DATA* in/out
Property: u32, // SETUP_DI_REGISTRY_PROPERTY
PropertyBuffer: *const u8, // BYTE* optional
PropertyBufferSize: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetupDiSetDeviceRegistryPropertyA(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, uint Property, IntPtr PropertyBuffer, uint PropertyBufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiSetDeviceRegistryPropertyA' -Namespace Win32 -PassThru
# $api::SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)#uselib "SETUPAPI.dll"
#func global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" sptr, sptr, sptr, sptr, sptr
; SetupDiSetDeviceRegistryPropertyA DeviceInfoSet, varptr(DeviceInfoData), Property, varptr(PropertyBuffer), PropertyBufferSize ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "sptr"
; Property : SETUP_DI_REGISTRY_PROPERTY -> "sptr"
; PropertyBuffer : BYTE* optional -> "sptr"
; PropertyBufferSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" sptr, var, int, var, int ; res = SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "var" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyBuffer : BYTE* optional -> "var" ; PropertyBufferSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" sptr, sptr, int, sptr, int ; res = SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, varptr(DeviceInfoData), Property, varptr(PropertyBuffer), PropertyBufferSize) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "sptr" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyBuffer : BYTE* optional -> "sptr" ; PropertyBufferSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiSetDeviceRegistryPropertyA(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SETUP_DI_REGISTRY_PROPERTY Property, BYTE* PropertyBuffer, DWORD PropertyBufferSize) #uselib "SETUPAPI.dll" #cfunc global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" intptr, var, int, var, int ; res = SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "var" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyBuffer : BYTE* optional -> "var" ; PropertyBufferSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiSetDeviceRegistryPropertyA(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SETUP_DI_REGISTRY_PROPERTY Property, BYTE* PropertyBuffer, DWORD PropertyBufferSize) #uselib "SETUPAPI.dll" #cfunc global SetupDiSetDeviceRegistryPropertyA "SetupDiSetDeviceRegistryPropertyA" intptr, intptr, int, intptr, int ; res = SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, varptr(DeviceInfoData), Property, varptr(PropertyBuffer), PropertyBufferSize) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* in/out -> "intptr" ; Property : SETUP_DI_REGISTRY_PROPERTY -> "int" ; PropertyBuffer : BYTE* optional -> "intptr" ; PropertyBufferSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiSetDeviceRegistryPropertyA = setupapi.NewProc("SetupDiSetDeviceRegistryPropertyA")
)
// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA* in/out), Property (SETUP_DI_REGISTRY_PROPERTY), PropertyBuffer (BYTE* optional), PropertyBufferSize (DWORD)
r1, _, err := procSetupDiSetDeviceRegistryPropertyA.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
uintptr(Property),
uintptr(PropertyBuffer),
uintptr(PropertyBufferSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiSetDeviceRegistryPropertyA(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA* in/out
Property: DWORD; // SETUP_DI_REGISTRY_PROPERTY
PropertyBuffer: Pointer; // BYTE* optional
PropertyBufferSize: DWORD // DWORD
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiSetDeviceRegistryPropertyA';result := DllCall("SETUPAPI\SetupDiSetDeviceRegistryPropertyA"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA* in/out
, "UInt", Property ; SETUP_DI_REGISTRY_PROPERTY
, "Ptr", PropertyBuffer ; BYTE* optional
, "UInt", PropertyBufferSize ; DWORD
, "Int") ; return: BOOL●SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize) = DLL("SETUPAPI.dll", "bool SetupDiSetDeviceRegistryPropertyA(int, void*, dword, void*, dword)")
# 呼び出し: SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* in/out -> "void*"
# Property : SETUP_DI_REGISTRY_PROPERTY -> "dword"
# PropertyBuffer : BYTE* optional -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "setupapi" fn SetupDiSetDeviceRegistryPropertyA(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: [*c]SP_DEVINFO_DATA, // SP_DEVINFO_DATA* in/out
Property: u32, // SETUP_DI_REGISTRY_PROPERTY
PropertyBuffer: [*c]u8, // BYTE* optional
PropertyBufferSize: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc SetupDiSetDeviceRegistryPropertyA(
DeviceInfoSet: int, # HDEVINFO
DeviceInfoData: ptr SP_DEVINFO_DATA, # SP_DEVINFO_DATA* in/out
Property: uint32, # SETUP_DI_REGISTRY_PROPERTY
PropertyBuffer: ptr uint8, # BYTE* optional
PropertyBufferSize: uint32 # DWORD
): int32 {.importc: "SetupDiSetDeviceRegistryPropertyA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupDiSetDeviceRegistryPropertyA(
ptrdiff_t DeviceInfoSet, // HDEVINFO
SP_DEVINFO_DATA* DeviceInfoData, // SP_DEVINFO_DATA* in/out
uint Property, // SETUP_DI_REGISTRY_PROPERTY
ubyte* PropertyBuffer, // BYTE* optional
uint PropertyBufferSize // DWORD
);ccall((:SetupDiSetDeviceRegistryPropertyA, "SETUPAPI.dll"), stdcall, Int32,
(Int, Ptr{SP_DEVINFO_DATA}, UInt32, Ptr{UInt8}, UInt32),
DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInfoData : SP_DEVINFO_DATA* in/out -> Ptr{SP_DEVINFO_DATA}
# Property : SETUP_DI_REGISTRY_PROPERTY -> UInt32
# PropertyBuffer : BYTE* optional -> Ptr{UInt8}
# PropertyBufferSize : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiSetDeviceRegistryPropertyA(
intptr_t DeviceInfoSet,
void* DeviceInfoData,
uint32_t Property,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
-- DeviceInfoSet : HDEVINFO
-- DeviceInfoData : SP_DEVINFO_DATA* in/out
-- Property : SETUP_DI_REGISTRY_PROPERTY
-- PropertyBuffer : BYTE* optional
-- PropertyBufferSize : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiSetDeviceRegistryPropertyA = lib.func('__stdcall', 'SetupDiSetDeviceRegistryPropertyA', 'int32_t', ['intptr_t', 'void *', 'uint32_t', 'uint8_t *', 'uint32_t']);
// SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* in/out -> 'void *'
// Property : SETUP_DI_REGISTRY_PROPERTY -> 'uint32_t'
// PropertyBuffer : BYTE* optional -> 'uint8_t *'
// PropertyBufferSize : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupDiSetDeviceRegistryPropertyA: { parameters: ["isize", "pointer", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* in/out -> "pointer"
// Property : SETUP_DI_REGISTRY_PROPERTY -> "u32"
// PropertyBuffer : BYTE* optional -> "pointer"
// PropertyBufferSize : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiSetDeviceRegistryPropertyA(
intptr_t DeviceInfoSet,
void* DeviceInfoData,
uint32_t Property,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize);
C, "SETUPAPI.dll");
// $ffi->SetupDiSetDeviceRegistryPropertyA(DeviceInfoSet, DeviceInfoData, Property, PropertyBuffer, PropertyBufferSize);
// DeviceInfoSet : HDEVINFO
// DeviceInfoData : SP_DEVINFO_DATA* in/out
// Property : SETUP_DI_REGISTRY_PROPERTY
// PropertyBuffer : BYTE* optional
// PropertyBufferSize : DWORD
// 構造体/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.ASCII_OPTIONS);
boolean SetupDiSetDeviceRegistryPropertyA(
long DeviceInfoSet, // HDEVINFO
Pointer DeviceInfoData, // SP_DEVINFO_DATA* in/out
int Property, // SETUP_DI_REGISTRY_PROPERTY
byte[] PropertyBuffer, // BYTE* optional
int PropertyBufferSize // DWORD
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupDiSetDeviceRegistryPropertyA = SetupDiSetDeviceRegistryPropertyA(
DeviceInfoSet : LibC::SSizeT, # HDEVINFO
DeviceInfoData : SP_DEVINFO_DATA*, # SP_DEVINFO_DATA* in/out
Property : UInt32, # SETUP_DI_REGISTRY_PROPERTY
PropertyBuffer : UInt8*, # BYTE* optional
PropertyBufferSize : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupDiSetDeviceRegistryPropertyANative = Int32 Function(IntPtr, Pointer<Void>, Uint32, Pointer<Uint8>, Uint32);
typedef SetupDiSetDeviceRegistryPropertyADart = int Function(int, Pointer<Void>, int, Pointer<Uint8>, int);
final SetupDiSetDeviceRegistryPropertyA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiSetDeviceRegistryPropertyANative, SetupDiSetDeviceRegistryPropertyADart>('SetupDiSetDeviceRegistryPropertyA');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* in/out -> Pointer<Void>
// Property : SETUP_DI_REGISTRY_PROPERTY -> Uint32
// PropertyBuffer : BYTE* optional -> Pointer<Uint8>
// PropertyBufferSize : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupDiSetDeviceRegistryPropertyA(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA* in/out
Property: DWORD; // SETUP_DI_REGISTRY_PROPERTY
PropertyBuffer: Pointer; // BYTE* optional
PropertyBufferSize: DWORD // DWORD
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiSetDeviceRegistryPropertyA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiSetDeviceRegistryPropertyA"
c_SetupDiSetDeviceRegistryPropertyA :: CIntPtr -> Ptr () -> Word32 -> Ptr Word8 -> Word32 -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* in/out -> Ptr ()
-- Property : SETUP_DI_REGISTRY_PROPERTY -> Word32
-- PropertyBuffer : BYTE* optional -> Ptr Word8
-- PropertyBufferSize : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupdisetdeviceregistrypropertya =
foreign "SetupDiSetDeviceRegistryPropertyA"
(intptr_t @-> (ptr void) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* in/out -> (ptr void) *)
(* Property : SETUP_DI_REGISTRY_PROPERTY -> uint32_t *)
(* PropertyBuffer : BYTE* optional -> (ptr uint8_t) *)
(* PropertyBufferSize : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupDiSetDeviceRegistryPropertyA" setup-di-set-device-registry-property-a :convention :stdcall) :int32
(device-info-set :int64) ; HDEVINFO
(device-info-data :pointer) ; SP_DEVINFO_DATA* in/out
(property :uint32) ; SETUP_DI_REGISTRY_PROPERTY
(property-buffer :pointer) ; BYTE* optional
(property-buffer-size :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupDiSetDeviceRegistryPropertyA = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiSetDeviceRegistryPropertyA(LPARAM DeviceInfoSet, LPVOID DeviceInfoData, DWORD Property, LPVOID PropertyBuffer, DWORD PropertyBufferSize)');
# my $ret = $SetupDiSetDeviceRegistryPropertyA->Call($DeviceInfoSet, $DeviceInfoData, $Property, $PropertyBuffer, $PropertyBufferSize);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* in/out -> LPVOID
# Property : SETUP_DI_REGISTRY_PROPERTY -> DWORD
# PropertyBuffer : BYTE* optional -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupDiSetDeviceRegistryPropertyW (Unicode版) — 指定デバイスのレジストリプロパティ値を設定する。
公式の関連項目
- f SetupDiGetClassRegistryPropertyA — 指定したデバイスセットアップクラスのレジストリプロパティを取得する。
- f SetupDiGetDeviceRegistryPropertyA — デバイスのPlug and Playレジストリプロパティを取得する。
- f SetupDiSetClassRegistryPropertyA — デバイスセットアップクラスのレジストリプロパティを設定する。