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

SetupDiSetClassRegistryPropertyA

関数
デバイスセットアップクラスのレジストリプロパティを設定する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

パラメーター

名前方向
ClassGuidGUID*in
PropertyDWORDin
PropertyBufferBYTE*inoptional
PropertyBufferSizeDWORDin
MachineNameLPCSTRinoptional
Reservedvoid*optional

戻り値の型: 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 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // BOOL
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';
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)。