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

SetupDiSetClassPropertyW

関数
デバイスクラスの指定プロパティ値を設定する。
DLLSETUPAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// SETUPAPI.dll
#include <windows.h>

BOOL SetupDiSetClassPropertyW(
    const GUID* ClassGuid,
    const DEVPROPKEY* PropertyKey,
    DEVPROPTYPE PropertyType,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    DWORD Flags
);

パラメーター

名前方向説明
ClassGuidGUID*inプロパティを設定する対象クラスのGUID。
PropertyKeyDEVPROPKEY*in設定するクラスプロパティを識別するDEVPROPKEY。
PropertyTypeDEVPROPTYPEin設定値のデータ型(DEVPROP_TYPE_*)。削除時はDEVPROP_TYPE_EMPTY。
PropertyBufferBYTE*inoptional設定する値を格納したバッファ。削除時はNULL可。
PropertyBufferSizeDWORDinPropertyBufferのバイトサイズ。削除時は0。
FlagsDWORDin対象クラス種別フラグ。DICLASSPROP_INSTALLERかDICLASSPROP_INTERFACEを指定する。

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll
#include <windows.h>

BOOL SetupDiSetClassPropertyW(
    const GUID* ClassGuid,
    const DEVPROPKEY* PropertyKey,
    DEVPROPTYPE PropertyType,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    DWORD Flags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiSetClassPropertyW(
    ref Guid ClassGuid,   // GUID*
    IntPtr PropertyKey,   // DEVPROPKEY*
    uint PropertyType,   // DEVPROPTYPE
    IntPtr PropertyBuffer,   // BYTE* optional
    uint PropertyBufferSize,   // DWORD
    uint Flags   // DWORD
);
<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiSetClassPropertyW(
    ByRef ClassGuid As Guid,   ' GUID*
    PropertyKey As IntPtr,   ' DEVPROPKEY*
    PropertyType As UInteger,   ' DEVPROPTYPE
    PropertyBuffer As IntPtr,   ' BYTE* optional
    PropertyBufferSize As UInteger,   ' DWORD
    Flags As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' ClassGuid : GUID*
' PropertyKey : DEVPROPKEY*
' PropertyType : DEVPROPTYPE
' PropertyBuffer : BYTE* optional
' PropertyBufferSize : DWORD
' Flags : DWORD
Declare PtrSafe Function SetupDiSetClassPropertyW Lib "setupapi" ( _
    ByVal ClassGuid As LongPtr, _
    ByVal PropertyKey As LongPtr, _
    ByVal PropertyType As Long, _
    ByVal PropertyBuffer As LongPtr, _
    ByVal PropertyBufferSize As Long, _
    ByVal Flags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiSetClassPropertyW = ctypes.windll.setupapi.SetupDiSetClassPropertyW
SetupDiSetClassPropertyW.restype = wintypes.BOOL
SetupDiSetClassPropertyW.argtypes = [
    ctypes.c_void_p,  # ClassGuid : GUID*
    ctypes.c_void_p,  # PropertyKey : DEVPROPKEY*
    wintypes.DWORD,  # PropertyType : DEVPROPTYPE
    ctypes.POINTER(ctypes.c_ubyte),  # PropertyBuffer : BYTE* optional
    wintypes.DWORD,  # PropertyBufferSize : DWORD
    wintypes.DWORD,  # Flags : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiSetClassPropertyW = Fiddle::Function.new(
  lib['SetupDiSetClassPropertyW'],
  [
    Fiddle::TYPE_VOIDP,  # ClassGuid : GUID*
    Fiddle::TYPE_VOIDP,  # PropertyKey : DEVPROPKEY*
    -Fiddle::TYPE_INT,  # PropertyType : DEVPROPTYPE
    Fiddle::TYPE_VOIDP,  # PropertyBuffer : BYTE* optional
    -Fiddle::TYPE_INT,  # PropertyBufferSize : DWORD
    -Fiddle::TYPE_INT,  # Flags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiSetClassPropertyW(
        ClassGuid: *const GUID,  // GUID*
        PropertyKey: *const DEVPROPKEY,  // DEVPROPKEY*
        PropertyType: u32,  // DEVPROPTYPE
        PropertyBuffer: *const u8,  // BYTE* optional
        PropertyBufferSize: u32,  // DWORD
        Flags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true)]
public static extern bool SetupDiSetClassPropertyW(ref Guid ClassGuid, IntPtr PropertyKey, uint PropertyType, IntPtr PropertyBuffer, uint PropertyBufferSize, uint Flags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiSetClassPropertyW' -Namespace Win32 -PassThru
# $api::SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
#uselib "SETUPAPI.dll"
#func global SetupDiSetClassPropertyW "SetupDiSetClassPropertyW" sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiSetClassPropertyW varptr(ClassGuid), varptr(PropertyKey), PropertyType, varptr(PropertyBuffer), PropertyBufferSize, Flags   ; 戻り値は stat
; ClassGuid : GUID* -> "sptr"
; PropertyKey : DEVPROPKEY* -> "sptr"
; PropertyType : DEVPROPTYPE -> "sptr"
; PropertyBuffer : BYTE* optional -> "sptr"
; PropertyBufferSize : DWORD -> "sptr"
; Flags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetClassPropertyW "SetupDiSetClassPropertyW" var, var, int, var, int, int
; res = SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
; ClassGuid : GUID* -> "var"
; PropertyKey : DEVPROPKEY* -> "var"
; PropertyType : DEVPROPTYPE -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; Flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiSetClassPropertyW(GUID* ClassGuid, DEVPROPKEY* PropertyKey, DEVPROPTYPE PropertyType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD Flags)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetClassPropertyW "SetupDiSetClassPropertyW" var, var, int, var, int, int
; res = SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
; ClassGuid : GUID* -> "var"
; PropertyKey : DEVPROPKEY* -> "var"
; PropertyType : DEVPROPTYPE -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; Flags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiSetClassPropertyW = setupapi.NewProc("SetupDiSetClassPropertyW")
)

// ClassGuid (GUID*), PropertyKey (DEVPROPKEY*), PropertyType (DEVPROPTYPE), PropertyBuffer (BYTE* optional), PropertyBufferSize (DWORD), Flags (DWORD)
r1, _, err := procSetupDiSetClassPropertyW.Call(
	uintptr(ClassGuid),
	uintptr(PropertyKey),
	uintptr(PropertyType),
	uintptr(PropertyBuffer),
	uintptr(PropertyBufferSize),
	uintptr(Flags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiSetClassPropertyW(
  ClassGuid: PGUID;   // GUID*
  PropertyKey: Pointer;   // DEVPROPKEY*
  PropertyType: DWORD;   // DEVPROPTYPE
  PropertyBuffer: Pointer;   // BYTE* optional
  PropertyBufferSize: DWORD;   // DWORD
  Flags: DWORD   // DWORD
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiSetClassPropertyW';
result := DllCall("SETUPAPI\SetupDiSetClassPropertyW"
    , "Ptr", ClassGuid   ; GUID*
    , "Ptr", PropertyKey   ; DEVPROPKEY*
    , "UInt", PropertyType   ; DEVPROPTYPE
    , "Ptr", PropertyBuffer   ; BYTE* optional
    , "UInt", PropertyBufferSize   ; DWORD
    , "UInt", Flags   ; DWORD
    , "Int")   ; return: BOOL
●SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags) = DLL("SETUPAPI.dll", "bool SetupDiSetClassPropertyW(void*, void*, dword, void*, dword, dword)")
# 呼び出し: SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
# ClassGuid : GUID* -> "void*"
# PropertyKey : DEVPROPKEY* -> "void*"
# PropertyType : DEVPROPTYPE -> "dword"
# PropertyBuffer : BYTE* optional -> "void*"
# PropertyBufferSize : DWORD -> "dword"
# Flags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupDiSetClassPropertyW(
    ClassGuid: [*c]GUID, // GUID*
    PropertyKey: [*c]DEVPROPKEY, // DEVPROPKEY*
    PropertyType: u32, // DEVPROPTYPE
    PropertyBuffer: [*c]u8, // BYTE* optional
    PropertyBufferSize: u32, // DWORD
    Flags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SetupDiSetClassPropertyW(
    ClassGuid: ptr GUID,  # GUID*
    PropertyKey: ptr DEVPROPKEY,  # DEVPROPKEY*
    PropertyType: uint32,  # DEVPROPTYPE
    PropertyBuffer: ptr uint8,  # BYTE* optional
    PropertyBufferSize: uint32,  # DWORD
    Flags: uint32  # DWORD
): int32 {.importc: "SetupDiSetClassPropertyW", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupDiSetClassPropertyW(
    GUID* ClassGuid,   // GUID*
    DEVPROPKEY* PropertyKey,   // DEVPROPKEY*
    uint PropertyType,   // DEVPROPTYPE
    ubyte* PropertyBuffer,   // BYTE* optional
    uint PropertyBufferSize,   // DWORD
    uint Flags   // DWORD
);
ccall((:SetupDiSetClassPropertyW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{GUID}, Ptr{DEVPROPKEY}, UInt32, Ptr{UInt8}, UInt32, UInt32),
      ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
# ClassGuid : GUID* -> Ptr{GUID}
# PropertyKey : DEVPROPKEY* -> Ptr{DEVPROPKEY}
# PropertyType : DEVPROPTYPE -> UInt32
# PropertyBuffer : BYTE* optional -> Ptr{UInt8}
# PropertyBufferSize : DWORD -> UInt32
# Flags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiSetClassPropertyW(
    void* ClassGuid,
    void* PropertyKey,
    uint32_t PropertyType,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    uint32_t Flags);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
-- ClassGuid : GUID*
-- PropertyKey : DEVPROPKEY*
-- PropertyType : DEVPROPTYPE
-- PropertyBuffer : BYTE* optional
-- PropertyBufferSize : DWORD
-- Flags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiSetClassPropertyW = lib.func('__stdcall', 'SetupDiSetClassPropertyW', 'int32_t', ['void *', 'void *', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t']);
// SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
// ClassGuid : GUID* -> 'void *'
// PropertyKey : DEVPROPKEY* -> 'void *'
// PropertyType : DEVPROPTYPE -> 'uint32_t'
// PropertyBuffer : BYTE* optional -> 'uint8_t *'
// PropertyBufferSize : DWORD -> 'uint32_t'
// Flags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiSetClassPropertyW: { parameters: ["pointer", "pointer", "u32", "pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags)
// ClassGuid : GUID* -> "pointer"
// PropertyKey : DEVPROPKEY* -> "pointer"
// PropertyType : DEVPROPTYPE -> "u32"
// PropertyBuffer : BYTE* optional -> "pointer"
// PropertyBufferSize : DWORD -> "u32"
// Flags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiSetClassPropertyW(
    void* ClassGuid,
    void* PropertyKey,
    uint32_t PropertyType,
    uint8_t* PropertyBuffer,
    uint32_t PropertyBufferSize,
    uint32_t Flags);
C, "SETUPAPI.dll");
// $ffi->SetupDiSetClassPropertyW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags);
// ClassGuid : GUID*
// PropertyKey : DEVPROPKEY*
// PropertyType : DEVPROPTYPE
// PropertyBuffer : BYTE* optional
// PropertyBufferSize : DWORD
// Flags : 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);
    boolean SetupDiSetClassPropertyW(
        Pointer ClassGuid,   // GUID*
        Pointer PropertyKey,   // DEVPROPKEY*
        int PropertyType,   // DEVPROPTYPE
        byte[] PropertyBuffer,   // BYTE* optional
        int PropertyBufferSize,   // DWORD
        int Flags   // DWORD
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiSetClassPropertyW = SetupDiSetClassPropertyW(
    ClassGuid : GUID*,   # GUID*
    PropertyKey : DEVPROPKEY*,   # DEVPROPKEY*
    PropertyType : UInt32,   # DEVPROPTYPE
    PropertyBuffer : UInt8*,   # BYTE* optional
    PropertyBufferSize : UInt32,   # DWORD
    Flags : 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 SetupDiSetClassPropertyWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Pointer<Uint8>, Uint32, Uint32);
typedef SetupDiSetClassPropertyWDart = int Function(Pointer<Void>, Pointer<Void>, int, Pointer<Uint8>, int, int);
final SetupDiSetClassPropertyW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiSetClassPropertyWNative, SetupDiSetClassPropertyWDart>('SetupDiSetClassPropertyW');
// ClassGuid : GUID* -> Pointer<Void>
// PropertyKey : DEVPROPKEY* -> Pointer<Void>
// PropertyType : DEVPROPTYPE -> Uint32
// PropertyBuffer : BYTE* optional -> Pointer<Uint8>
// PropertyBufferSize : DWORD -> Uint32
// Flags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupDiSetClassPropertyW(
  ClassGuid: PGUID;   // GUID*
  PropertyKey: Pointer;   // DEVPROPKEY*
  PropertyType: DWORD;   // DEVPROPTYPE
  PropertyBuffer: Pointer;   // BYTE* optional
  PropertyBufferSize: DWORD;   // DWORD
  Flags: DWORD   // DWORD
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiSetClassPropertyW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiSetClassPropertyW"
  c_SetupDiSetClassPropertyW :: Ptr () -> Ptr () -> Word32 -> Ptr Word8 -> Word32 -> Word32 -> IO CInt
-- ClassGuid : GUID* -> Ptr ()
-- PropertyKey : DEVPROPKEY* -> Ptr ()
-- PropertyType : DEVPROPTYPE -> Word32
-- PropertyBuffer : BYTE* optional -> Ptr Word8
-- PropertyBufferSize : DWORD -> Word32
-- Flags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdisetclasspropertyw =
  foreign "SetupDiSetClassPropertyW"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* ClassGuid : GUID* -> (ptr void) *)
(* PropertyKey : DEVPROPKEY* -> (ptr void) *)
(* PropertyType : DEVPROPTYPE -> uint32_t *)
(* PropertyBuffer : BYTE* optional -> (ptr uint8_t) *)
(* PropertyBufferSize : DWORD -> uint32_t *)
(* Flags : 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 ("SetupDiSetClassPropertyW" setup-di-set-class-property-w :convention :stdcall) :int32
  (class-guid :pointer)   ; GUID*
  (property-key :pointer)   ; DEVPROPKEY*
  (property-type :uint32)   ; DEVPROPTYPE
  (property-buffer :pointer)   ; BYTE* optional
  (property-buffer-size :uint32)   ; DWORD
  (flags :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiSetClassPropertyW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiSetClassPropertyW(LPVOID ClassGuid, LPVOID PropertyKey, DWORD PropertyType, LPVOID PropertyBuffer, DWORD PropertyBufferSize, DWORD Flags)');
# my $ret = $SetupDiSetClassPropertyW->Call($ClassGuid, $PropertyKey, $PropertyType, $PropertyBuffer, $PropertyBufferSize, $Flags);
# ClassGuid : GUID* -> LPVOID
# PropertyKey : DEVPROPKEY* -> LPVOID
# PropertyType : DEVPROPTYPE -> DWORD
# PropertyBuffer : BYTE* optional -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# Flags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型