ホーム › Devices.DeviceAndDriverInstallation › SetupDiSetClassRegistryPropertyA
SetupDiSetClassRegistryPropertyA
関数デバイスセットアップクラスのレジストリプロパティを設定する。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiSetClassRegistryPropertyA(
const GUID* ClassGuid,
DWORD Property,
const BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize,
LPCSTR MachineName, // optional
void* Reserved // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ClassGuid | GUID* | in | レジストリプロパティを設定する対象クラスのGUID。 |
| Property | DWORD | in | 設定するクラスプロパティの種別。SPCRP_*値を指定する。 |
| PropertyBuffer | BYTE* | inoptional | 設定する値を格納したバッファ(ANSI)。削除時はNULL可。 |
| PropertyBufferSize | DWORD | in | PropertyBufferのバイトサイズ。削除時は0。 |
| MachineName | LPCSTR | inoptional | 対象リモートコンピュータ名(ANSI)。NULL指定でローカルマシンを対象とする。 |
| Reserved | void* | optional | 予約済み。NULLを指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiSetClassRegistryPropertyA(
const GUID* ClassGuid,
DWORD Property,
const BYTE* PropertyBuffer, // optional
DWORD PropertyBufferSize,
LPCSTR MachineName, // optional
void* Reserved // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiSetClassRegistryPropertyA(
ref Guid ClassGuid, // GUID*
uint Property, // DWORD
IntPtr PropertyBuffer, // BYTE* optional
uint PropertyBufferSize, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string MachineName, // LPCSTR optional
IntPtr Reserved // void* optional
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiSetClassRegistryPropertyA(
ByRef ClassGuid As Guid, ' GUID*
[Property] As UInteger, ' DWORD
PropertyBuffer As IntPtr, ' BYTE* optional
PropertyBufferSize As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> MachineName As String, ' LPCSTR optional
Reserved As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' ClassGuid : GUID*
' Property : DWORD
' PropertyBuffer : BYTE* optional
' PropertyBufferSize : DWORD
' MachineName : LPCSTR optional
' Reserved : void* optional
Declare PtrSafe Function SetupDiSetClassRegistryPropertyA Lib "setupapi" ( _
ByVal ClassGuid As LongPtr, _
ByVal Property As Long, _
ByVal PropertyBuffer As LongPtr, _
ByVal PropertyBufferSize As Long, _
ByVal MachineName As String, _
ByVal Reserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiSetClassRegistryPropertyA = ctypes.windll.setupapi.SetupDiSetClassRegistryPropertyA
SetupDiSetClassRegistryPropertyA.restype = wintypes.BOOL
SetupDiSetClassRegistryPropertyA.argtypes = [
ctypes.c_void_p, # ClassGuid : GUID*
wintypes.DWORD, # Property : DWORD
ctypes.POINTER(ctypes.c_ubyte), # PropertyBuffer : BYTE* optional
wintypes.DWORD, # PropertyBufferSize : DWORD
wintypes.LPCSTR, # MachineName : LPCSTR optional
ctypes.POINTER(None), # Reserved : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiSetClassRegistryPropertyA = Fiddle::Function.new(
lib['SetupDiSetClassRegistryPropertyA'],
[
Fiddle::TYPE_VOIDP, # ClassGuid : GUID*
-Fiddle::TYPE_INT, # Property : DWORD
Fiddle::TYPE_VOIDP, # PropertyBuffer : BYTE* optional
-Fiddle::TYPE_INT, # PropertyBufferSize : DWORD
Fiddle::TYPE_VOIDP, # MachineName : LPCSTR optional
Fiddle::TYPE_VOIDP, # Reserved : void* optional
],
Fiddle::TYPE_INT)#[link(name = "setupapi")]
extern "system" {
fn SetupDiSetClassRegistryPropertyA(
ClassGuid: *const GUID, // GUID*
Property: u32, // DWORD
PropertyBuffer: *const u8, // BYTE* optional
PropertyBufferSize: u32, // DWORD
MachineName: *const u8, // LPCSTR optional
Reserved: *mut () // void* optional
) -> 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 SetupDiSetClassRegistryPropertyA(ref Guid ClassGuid, uint Property, IntPtr PropertyBuffer, uint PropertyBufferSize, [MarshalAs(UnmanagedType.LPStr)] string MachineName, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiSetClassRegistryPropertyA' -Namespace Win32 -PassThru
# $api::SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)#uselib "SETUPAPI.dll"
#func global SetupDiSetClassRegistryPropertyA "SetupDiSetClassRegistryPropertyA" sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiSetClassRegistryPropertyA varptr(ClassGuid), Property, varptr(PropertyBuffer), PropertyBufferSize, MachineName, Reserved ; 戻り値は stat
; ClassGuid : GUID* -> "sptr"
; Property : DWORD -> "sptr"
; PropertyBuffer : BYTE* optional -> "sptr"
; PropertyBufferSize : DWORD -> "sptr"
; MachineName : LPCSTR optional -> "sptr"
; Reserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiSetClassRegistryPropertyA "SetupDiSetClassRegistryPropertyA" var, int, var, int, str, sptr ; res = SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved) ; ClassGuid : GUID* -> "var" ; Property : DWORD -> "int" ; PropertyBuffer : BYTE* optional -> "var" ; PropertyBufferSize : DWORD -> "int" ; MachineName : LPCSTR optional -> "str" ; Reserved : void* optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiSetClassRegistryPropertyA "SetupDiSetClassRegistryPropertyA" sptr, int, sptr, int, str, sptr ; res = SetupDiSetClassRegistryPropertyA(varptr(ClassGuid), Property, varptr(PropertyBuffer), PropertyBufferSize, MachineName, Reserved) ; ClassGuid : GUID* -> "sptr" ; Property : DWORD -> "int" ; PropertyBuffer : BYTE* optional -> "sptr" ; PropertyBufferSize : DWORD -> "int" ; MachineName : LPCSTR optional -> "str" ; Reserved : void* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiSetClassRegistryPropertyA(GUID* ClassGuid, DWORD Property, BYTE* PropertyBuffer, DWORD PropertyBufferSize, LPCSTR MachineName, void* Reserved) #uselib "SETUPAPI.dll" #cfunc global SetupDiSetClassRegistryPropertyA "SetupDiSetClassRegistryPropertyA" var, int, var, int, str, intptr ; res = SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved) ; ClassGuid : GUID* -> "var" ; Property : DWORD -> "int" ; PropertyBuffer : BYTE* optional -> "var" ; PropertyBufferSize : DWORD -> "int" ; MachineName : LPCSTR optional -> "str" ; Reserved : void* optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiSetClassRegistryPropertyA(GUID* ClassGuid, DWORD Property, BYTE* PropertyBuffer, DWORD PropertyBufferSize, LPCSTR MachineName, void* Reserved) #uselib "SETUPAPI.dll" #cfunc global SetupDiSetClassRegistryPropertyA "SetupDiSetClassRegistryPropertyA" intptr, int, intptr, int, str, intptr ; res = SetupDiSetClassRegistryPropertyA(varptr(ClassGuid), Property, varptr(PropertyBuffer), PropertyBufferSize, MachineName, Reserved) ; ClassGuid : GUID* -> "intptr" ; Property : DWORD -> "int" ; PropertyBuffer : BYTE* optional -> "intptr" ; PropertyBufferSize : DWORD -> "int" ; MachineName : LPCSTR optional -> "str" ; Reserved : void* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiSetClassRegistryPropertyA = setupapi.NewProc("SetupDiSetClassRegistryPropertyA")
)
// ClassGuid (GUID*), Property (DWORD), PropertyBuffer (BYTE* optional), PropertyBufferSize (DWORD), MachineName (LPCSTR optional), Reserved (void* optional)
r1, _, err := procSetupDiSetClassRegistryPropertyA.Call(
uintptr(ClassGuid),
uintptr(Property),
uintptr(PropertyBuffer),
uintptr(PropertyBufferSize),
uintptr(unsafe.Pointer(windows.BytePtrFromString(MachineName))),
uintptr(Reserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiSetClassRegistryPropertyA(
ClassGuid: PGUID; // GUID*
Property: DWORD; // DWORD
PropertyBuffer: Pointer; // BYTE* optional
PropertyBufferSize: DWORD; // DWORD
MachineName: PAnsiChar; // LPCSTR optional
Reserved: Pointer // void* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiSetClassRegistryPropertyA';result := DllCall("SETUPAPI\SetupDiSetClassRegistryPropertyA"
, "Ptr", ClassGuid ; GUID*
, "UInt", Property ; DWORD
, "Ptr", PropertyBuffer ; BYTE* optional
, "UInt", PropertyBufferSize ; DWORD
, "AStr", MachineName ; LPCSTR optional
, "Ptr", Reserved ; void* optional
, "Int") ; return: BOOL●SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved) = DLL("SETUPAPI.dll", "bool SetupDiSetClassRegistryPropertyA(void*, dword, void*, dword, char*, void*)")
# 呼び出し: SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
# ClassGuid : GUID* -> "void*"
# Property : DWORD -> "dword"
# PropertyBuffer : BYTE* optional -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# MachineName : LPCSTR optional -> "char*"
# Reserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "setupapi" fn SetupDiSetClassRegistryPropertyA(
ClassGuid: [*c]GUID, // GUID*
Property: u32, // DWORD
PropertyBuffer: [*c]u8, // BYTE* optional
PropertyBufferSize: u32, // DWORD
MachineName: [*c]const u8, // LPCSTR optional
Reserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc SetupDiSetClassRegistryPropertyA(
ClassGuid: ptr GUID, # GUID*
Property: uint32, # DWORD
PropertyBuffer: ptr uint8, # BYTE* optional
PropertyBufferSize: uint32, # DWORD
MachineName: cstring, # LPCSTR optional
Reserved: pointer # void* optional
): int32 {.importc: "SetupDiSetClassRegistryPropertyA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupDiSetClassRegistryPropertyA(
GUID* ClassGuid, // GUID*
uint Property, // DWORD
ubyte* PropertyBuffer, // BYTE* optional
uint PropertyBufferSize, // DWORD
const(char)* MachineName, // LPCSTR optional
void* Reserved // void* optional
);ccall((:SetupDiSetClassRegistryPropertyA, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{GUID}, UInt32, Ptr{UInt8}, UInt32, Cstring, Ptr{Cvoid}),
ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
# ClassGuid : GUID* -> Ptr{GUID}
# Property : DWORD -> UInt32
# PropertyBuffer : BYTE* optional -> Ptr{UInt8}
# PropertyBufferSize : DWORD -> UInt32
# MachineName : LPCSTR optional -> Cstring
# Reserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiSetClassRegistryPropertyA(
void* ClassGuid,
uint32_t Property,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize,
const char* MachineName,
void* Reserved);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
-- ClassGuid : GUID*
-- Property : DWORD
-- PropertyBuffer : BYTE* optional
-- PropertyBufferSize : DWORD
-- MachineName : LPCSTR optional
-- Reserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiSetClassRegistryPropertyA = lib.func('__stdcall', 'SetupDiSetClassRegistryPropertyA', 'int32_t', ['void *', 'uint32_t', 'uint8_t *', 'uint32_t', 'str', 'void *']);
// SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
// ClassGuid : GUID* -> 'void *'
// Property : DWORD -> 'uint32_t'
// PropertyBuffer : BYTE* optional -> 'uint8_t *'
// PropertyBufferSize : DWORD -> 'uint32_t'
// MachineName : LPCSTR optional -> 'str'
// Reserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupDiSetClassRegistryPropertyA: { parameters: ["pointer", "u32", "pointer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
// ClassGuid : GUID* -> "pointer"
// Property : DWORD -> "u32"
// PropertyBuffer : BYTE* optional -> "pointer"
// PropertyBufferSize : DWORD -> "u32"
// MachineName : LPCSTR optional -> "buffer"
// Reserved : void* optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiSetClassRegistryPropertyA(
void* ClassGuid,
uint32_t Property,
uint8_t* PropertyBuffer,
uint32_t PropertyBufferSize,
const char* MachineName,
void* Reserved);
C, "SETUPAPI.dll");
// $ffi->SetupDiSetClassRegistryPropertyA(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved);
// ClassGuid : GUID*
// Property : DWORD
// PropertyBuffer : BYTE* optional
// PropertyBufferSize : DWORD
// MachineName : LPCSTR optional
// Reserved : void* 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.ASCII_OPTIONS);
boolean SetupDiSetClassRegistryPropertyA(
Pointer ClassGuid, // GUID*
int Property, // DWORD
byte[] PropertyBuffer, // BYTE* optional
int PropertyBufferSize, // DWORD
String MachineName, // LPCSTR optional
Pointer Reserved // void* optional
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupDiSetClassRegistryPropertyA = SetupDiSetClassRegistryPropertyA(
ClassGuid : GUID*, # GUID*
Property : UInt32, # DWORD
PropertyBuffer : UInt8*, # BYTE* optional
PropertyBufferSize : UInt32, # DWORD
MachineName : UInt8*, # LPCSTR optional
Reserved : Void* # void* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupDiSetClassRegistryPropertyANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Uint8>, Uint32, Pointer<Utf8>, Pointer<Void>);
typedef SetupDiSetClassRegistryPropertyADart = int Function(Pointer<Void>, int, Pointer<Uint8>, int, Pointer<Utf8>, Pointer<Void>);
final SetupDiSetClassRegistryPropertyA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiSetClassRegistryPropertyANative, SetupDiSetClassRegistryPropertyADart>('SetupDiSetClassRegistryPropertyA');
// ClassGuid : GUID* -> Pointer<Void>
// Property : DWORD -> Uint32
// PropertyBuffer : BYTE* optional -> Pointer<Uint8>
// PropertyBufferSize : DWORD -> Uint32
// MachineName : LPCSTR optional -> Pointer<Utf8>
// Reserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupDiSetClassRegistryPropertyA(
ClassGuid: PGUID; // GUID*
Property: DWORD; // DWORD
PropertyBuffer: Pointer; // BYTE* optional
PropertyBufferSize: DWORD; // DWORD
MachineName: PAnsiChar; // LPCSTR optional
Reserved: Pointer // void* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiSetClassRegistryPropertyA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiSetClassRegistryPropertyA"
c_SetupDiSetClassRegistryPropertyA :: Ptr () -> Word32 -> Ptr Word8 -> Word32 -> CString -> Ptr () -> IO CInt
-- ClassGuid : GUID* -> Ptr ()
-- Property : DWORD -> Word32
-- PropertyBuffer : BYTE* optional -> Ptr Word8
-- PropertyBufferSize : DWORD -> Word32
-- MachineName : LPCSTR optional -> CString
-- Reserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupdisetclassregistrypropertya =
foreign "SetupDiSetClassRegistryPropertyA"
((ptr void) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> string @-> (ptr void) @-> returning int32_t)
(* ClassGuid : GUID* -> (ptr void) *)
(* Property : DWORD -> uint32_t *)
(* PropertyBuffer : BYTE* optional -> (ptr uint8_t) *)
(* PropertyBufferSize : DWORD -> uint32_t *)
(* MachineName : LPCSTR optional -> string *)
(* Reserved : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupDiSetClassRegistryPropertyA" setup-di-set-class-registry-property-a :convention :stdcall) :int32
(class-guid :pointer) ; GUID*
(property :uint32) ; DWORD
(property-buffer :pointer) ; BYTE* optional
(property-buffer-size :uint32) ; DWORD
(machine-name :string) ; LPCSTR optional
(reserved :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupDiSetClassRegistryPropertyA = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiSetClassRegistryPropertyA(LPVOID ClassGuid, DWORD Property, LPVOID PropertyBuffer, DWORD PropertyBufferSize, LPCSTR MachineName, LPVOID Reserved)');
# my $ret = $SetupDiSetClassRegistryPropertyA->Call($ClassGuid, $Property, $PropertyBuffer, $PropertyBufferSize, $MachineName, $Reserved);
# ClassGuid : GUID* -> LPVOID
# Property : DWORD -> DWORD
# PropertyBuffer : BYTE* optional -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# MachineName : LPCSTR optional -> LPCSTR
# Reserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupDiSetClassRegistryPropertyW (Unicode版) — デバイスセットアップクラスのレジストリプロパティを設定する。