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

SetupDiSetClassRegistryPropertyW

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

シグネチャ

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupDiSetClassRegistryPropertyW(
    const GUID* ClassGuid,
    DWORD Property,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);

パラメーター

名前方向説明
ClassGuidGUID*inレジストリプロパティを設定する対象クラスのGUID。
PropertyDWORDin設定するクラスプロパティの種別。SPCRP_*値を指定する。
PropertyBufferBYTE*inoptional設定する値を格納したバッファ(Unicode)。削除時はNULL可。
PropertyBufferSizeDWORDinPropertyBufferのバイトサイズ。削除時は0。
MachineNameLPCWSTRinoptional対象リモートコンピュータ名(Unicode)。NULL指定でローカルマシンを対象とする。
Reservedvoid*optional予約済み。NULLを指定する。

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupDiSetClassRegistryPropertyW(
    const GUID* ClassGuid,
    DWORD Property,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiSetClassRegistryPropertyW(
    ref Guid ClassGuid,   // GUID*
    uint Property,   // DWORD
    IntPtr PropertyBuffer,   // BYTE* optional
    uint PropertyBufferSize,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string MachineName,   // LPCWSTR optional
    IntPtr Reserved   // void* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiSetClassRegistryPropertyW(
    ByRef ClassGuid As Guid,   ' GUID*
    [Property] As UInteger,   ' DWORD
    PropertyBuffer As IntPtr,   ' BYTE* optional
    PropertyBufferSize As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> MachineName As String,   ' LPCWSTR optional
    Reserved As IntPtr   ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' ClassGuid : GUID*
' Property : DWORD
' PropertyBuffer : BYTE* optional
' PropertyBufferSize : DWORD
' MachineName : LPCWSTR optional
' Reserved : void* optional
Declare PtrSafe Function SetupDiSetClassRegistryPropertyW Lib "setupapi" ( _
    ByVal ClassGuid As LongPtr, _
    ByVal Property As Long, _
    ByVal PropertyBuffer As LongPtr, _
    ByVal PropertyBufferSize As Long, _
    ByVal MachineName As LongPtr, _
    ByVal Reserved As LongPtr) As Long
' 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

SetupDiSetClassRegistryPropertyW = ctypes.windll.setupapi.SetupDiSetClassRegistryPropertyW
SetupDiSetClassRegistryPropertyW.restype = wintypes.BOOL
SetupDiSetClassRegistryPropertyW.argtypes = [
    ctypes.c_void_p,  # ClassGuid : GUID*
    wintypes.DWORD,  # Property : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # PropertyBuffer : BYTE* optional
    wintypes.DWORD,  # PropertyBufferSize : DWORD
    wintypes.LPCWSTR,  # MachineName : LPCWSTR 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')
SetupDiSetClassRegistryPropertyW = Fiddle::Function.new(
  lib['SetupDiSetClassRegistryPropertyW'],
  [
    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 : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # Reserved : void* optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiSetClassRegistryPropertyW(
        ClassGuid: *const GUID,  // GUID*
        Property: u32,  // DWORD
        PropertyBuffer: *const u8,  // BYTE* optional
        PropertyBufferSize: u32,  // DWORD
        MachineName: *const u16,  // LPCWSTR 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.Unicode, SetLastError = true)]
public static extern bool SetupDiSetClassRegistryPropertyW(ref Guid ClassGuid, uint Property, IntPtr PropertyBuffer, uint PropertyBufferSize, [MarshalAs(UnmanagedType.LPWStr)] string MachineName, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiSetClassRegistryPropertyW' -Namespace Win32 -PassThru
# $api::SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
#uselib "SETUPAPI.dll"
#func global SetupDiSetClassRegistryPropertyW "SetupDiSetClassRegistryPropertyW" wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiSetClassRegistryPropertyW varptr(ClassGuid), Property, varptr(PropertyBuffer), PropertyBufferSize, MachineName, Reserved   ; 戻り値は stat
; ClassGuid : GUID* -> "wptr"
; Property : DWORD -> "wptr"
; PropertyBuffer : BYTE* optional -> "wptr"
; PropertyBufferSize : DWORD -> "wptr"
; MachineName : LPCWSTR optional -> "wptr"
; Reserved : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetClassRegistryPropertyW "SetupDiSetClassRegistryPropertyW" var, int, var, int, wstr, sptr
; res = SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
; ClassGuid : GUID* -> "var"
; Property : DWORD -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiSetClassRegistryPropertyW(GUID* ClassGuid, DWORD Property, BYTE* PropertyBuffer, DWORD PropertyBufferSize, LPCWSTR MachineName, void* Reserved)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetClassRegistryPropertyW "SetupDiSetClassRegistryPropertyW" var, int, var, int, wstr, intptr
; res = SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
; ClassGuid : GUID* -> "var"
; Property : DWORD -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiSetClassRegistryPropertyW = setupapi.NewProc("SetupDiSetClassRegistryPropertyW")
)

// ClassGuid (GUID*), Property (DWORD), PropertyBuffer (BYTE* optional), PropertyBufferSize (DWORD), MachineName (LPCWSTR optional), Reserved (void* optional)
r1, _, err := procSetupDiSetClassRegistryPropertyW.Call(
	uintptr(ClassGuid),
	uintptr(Property),
	uintptr(PropertyBuffer),
	uintptr(PropertyBufferSize),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(MachineName))),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiSetClassRegistryPropertyW(
  ClassGuid: PGUID;   // GUID*
  Property: DWORD;   // DWORD
  PropertyBuffer: Pointer;   // BYTE* optional
  PropertyBufferSize: DWORD;   // DWORD
  MachineName: PWideChar;   // LPCWSTR optional
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiSetClassRegistryPropertyW';
result := DllCall("SETUPAPI\SetupDiSetClassRegistryPropertyW"
    , "Ptr", ClassGuid   ; GUID*
    , "UInt", Property   ; DWORD
    , "Ptr", PropertyBuffer   ; BYTE* optional
    , "UInt", PropertyBufferSize   ; DWORD
    , "WStr", MachineName   ; LPCWSTR optional
    , "Ptr", Reserved   ; void* optional
    , "Int")   ; return: BOOL
●SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved) = DLL("SETUPAPI.dll", "bool SetupDiSetClassRegistryPropertyW(void*, dword, void*, dword, char*, void*)")
# 呼び出し: SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
# ClassGuid : GUID* -> "void*"
# Property : DWORD -> "dword"
# PropertyBuffer : BYTE* optional -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# MachineName : LPCWSTR optional -> "char*"
# Reserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn SetupDiSetClassRegistryPropertyW(
    ClassGuid: [*c]GUID, // GUID*
    Property: u32, // DWORD
    PropertyBuffer: [*c]u8, // BYTE* optional
    PropertyBufferSize: u32, // DWORD
    MachineName: [*c]const u16, // LPCWSTR optional
    Reserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupDiSetClassRegistryPropertyW(
    ClassGuid: ptr GUID,  # GUID*
    Property: uint32,  # DWORD
    PropertyBuffer: ptr uint8,  # BYTE* optional
    PropertyBufferSize: uint32,  # DWORD
    MachineName: WideCString,  # LPCWSTR optional
    Reserved: pointer  # void* optional
): int32 {.importc: "SetupDiSetClassRegistryPropertyW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
int SetupDiSetClassRegistryPropertyW(
    GUID* ClassGuid,   // GUID*
    uint Property,   // DWORD
    ubyte* PropertyBuffer,   // BYTE* optional
    uint PropertyBufferSize,   // DWORD
    const(wchar)* MachineName,   // LPCWSTR optional
    void* Reserved   // void* optional
);
ccall((:SetupDiSetClassRegistryPropertyW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{GUID}, UInt32, Ptr{UInt8}, UInt32, Cwstring, Ptr{Cvoid}),
      ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
# ClassGuid : GUID* -> Ptr{GUID}
# Property : DWORD -> UInt32
# PropertyBuffer : BYTE* optional -> Ptr{UInt8}
# PropertyBufferSize : DWORD -> UInt32
# MachineName : LPCWSTR optional -> Cwstring
# Reserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiSetClassRegistryPropertyW(
    void* ClassGuid,
    uint32_t Property,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    const uint16_t* MachineName,
    void* Reserved);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
-- ClassGuid : GUID*
-- Property : DWORD
-- PropertyBuffer : BYTE* optional
-- PropertyBufferSize : DWORD
-- MachineName : LPCWSTR optional
-- Reserved : void* 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 SetupDiSetClassRegistryPropertyW = lib.func('__stdcall', 'SetupDiSetClassRegistryPropertyW', 'int32_t', ['void *', 'uint32_t', 'uint8_t *', 'uint32_t', 'str16', 'void *']);
// SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
// ClassGuid : GUID* -> 'void *'
// Property : DWORD -> 'uint32_t'
// PropertyBuffer : BYTE* optional -> 'uint8_t *'
// PropertyBufferSize : DWORD -> 'uint32_t'
// MachineName : LPCWSTR optional -> 'str16'
// Reserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiSetClassRegistryPropertyW: { parameters: ["pointer", "u32", "pointer", "u32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved)
// ClassGuid : GUID* -> "pointer"
// Property : DWORD -> "u32"
// PropertyBuffer : BYTE* optional -> "pointer"
// PropertyBufferSize : DWORD -> "u32"
// MachineName : LPCWSTR optional -> "buffer"
// Reserved : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiSetClassRegistryPropertyW(
    void* ClassGuid,
    uint32_t Property,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    const uint16_t* MachineName,
    void* Reserved);
C, "SETUPAPI.dll");
// $ffi->SetupDiSetClassRegistryPropertyW(ClassGuid, Property, PropertyBuffer, PropertyBufferSize, MachineName, Reserved);
// ClassGuid : GUID*
// Property : DWORD
// PropertyBuffer : BYTE* optional
// PropertyBufferSize : DWORD
// MachineName : LPCWSTR 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.UNICODE_OPTIONS);
    boolean SetupDiSetClassRegistryPropertyW(
        Pointer ClassGuid,   // GUID*
        int Property,   // DWORD
        byte[] PropertyBuffer,   // BYTE* optional
        int PropertyBufferSize,   // DWORD
        WString MachineName,   // LPCWSTR optional
        Pointer Reserved   // void* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiSetClassRegistryPropertyW = SetupDiSetClassRegistryPropertyW(
    ClassGuid : GUID*,   # GUID*
    Property : UInt32,   # DWORD
    PropertyBuffer : UInt8*,   # BYTE* optional
    PropertyBufferSize : UInt32,   # DWORD
    MachineName : UInt16*,   # LPCWSTR 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 SetupDiSetClassRegistryPropertyWNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Uint8>, Uint32, Pointer<Utf16>, Pointer<Void>);
typedef SetupDiSetClassRegistryPropertyWDart = int Function(Pointer<Void>, int, Pointer<Uint8>, int, Pointer<Utf16>, Pointer<Void>);
final SetupDiSetClassRegistryPropertyW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiSetClassRegistryPropertyWNative, SetupDiSetClassRegistryPropertyWDart>('SetupDiSetClassRegistryPropertyW');
// ClassGuid : GUID* -> Pointer<Void>
// Property : DWORD -> Uint32
// PropertyBuffer : BYTE* optional -> Pointer<Uint8>
// PropertyBufferSize : DWORD -> Uint32
// MachineName : LPCWSTR optional -> Pointer<Utf16>
// Reserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupDiSetClassRegistryPropertyW(
  ClassGuid: PGUID;   // GUID*
  Property: DWORD;   // DWORD
  PropertyBuffer: Pointer;   // BYTE* optional
  PropertyBufferSize: DWORD;   // DWORD
  MachineName: PWideChar;   // LPCWSTR optional
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiSetClassRegistryPropertyW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiSetClassRegistryPropertyW"
  c_SetupDiSetClassRegistryPropertyW :: Ptr () -> Word32 -> Ptr Word8 -> Word32 -> CWString -> Ptr () -> IO CInt
-- ClassGuid : GUID* -> Ptr ()
-- Property : DWORD -> Word32
-- PropertyBuffer : BYTE* optional -> Ptr Word8
-- PropertyBufferSize : DWORD -> Word32
-- MachineName : LPCWSTR optional -> CWString
-- Reserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdisetclassregistrypropertyw =
  foreign "SetupDiSetClassRegistryPropertyW"
    ((ptr void) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* ClassGuid : GUID* -> (ptr void) *)
(* Property : DWORD -> uint32_t *)
(* PropertyBuffer : BYTE* optional -> (ptr uint8_t) *)
(* PropertyBufferSize : DWORD -> uint32_t *)
(* MachineName : LPCWSTR optional -> (ptr uint16_t) *)
(* 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 ("SetupDiSetClassRegistryPropertyW" setup-di-set-class-registry-property-w :convention :stdcall) :int32
  (class-guid :pointer)   ; GUID*
  (property :uint32)   ; DWORD
  (property-buffer :pointer)   ; BYTE* optional
  (property-buffer-size :uint32)   ; DWORD
  (machine-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (reserved :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiSetClassRegistryPropertyW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiSetClassRegistryPropertyW(LPVOID ClassGuid, DWORD Property, LPVOID PropertyBuffer, DWORD PropertyBufferSize, LPCWSTR MachineName, LPVOID Reserved)');
# my $ret = $SetupDiSetClassRegistryPropertyW->Call($ClassGuid, $Property, $PropertyBuffer, $PropertyBufferSize, $MachineName, $Reserved);
# ClassGuid : GUID* -> LPVOID
# Property : DWORD -> DWORD
# PropertyBuffer : BYTE* optional -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# MachineName : LPCWSTR optional -> LPCWSTR
# Reserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い