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

SetupDiSetClassPropertyExW

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

シグネチャ

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

BOOL SetupDiSetClassPropertyExW(
    const GUID* ClassGuid,
    const DEVPROPKEY* PropertyKey,
    DEVPROPTYPE PropertyType,
    const BYTE* PropertyBuffer,   // optional
    DWORD PropertyBufferSize,
    DWORD Flags,
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);

パラメーター

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

戻り値の型: BOOL

各言語での呼び出し定義

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

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

SetupDiSetClassPropertyExW = ctypes.windll.setupapi.SetupDiSetClassPropertyExW
SetupDiSetClassPropertyExW.restype = wintypes.BOOL
SetupDiSetClassPropertyExW.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
    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')
SetupDiSetClassPropertyExW = Fiddle::Function.new(
  lib['SetupDiSetClassPropertyExW'],
  [
    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_VOIDP,  # MachineName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # Reserved : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiSetClassPropertyExW(
        ClassGuid: *const GUID,  // GUID*
        PropertyKey: *const DEVPROPKEY,  // DEVPROPKEY*
        PropertyType: u32,  // DEVPROPTYPE
        PropertyBuffer: *const u8,  // BYTE* optional
        PropertyBufferSize: u32,  // DWORD
        Flags: 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", SetLastError = true)]
public static extern bool SetupDiSetClassPropertyExW(ref Guid ClassGuid, IntPtr PropertyKey, uint PropertyType, IntPtr PropertyBuffer, uint PropertyBufferSize, uint Flags, [MarshalAs(UnmanagedType.LPWStr)] string MachineName, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiSetClassPropertyExW' -Namespace Win32 -PassThru
# $api::SetupDiSetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags, MachineName, Reserved)
#uselib "SETUPAPI.dll"
#func global SetupDiSetClassPropertyExW "SetupDiSetClassPropertyExW" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiSetClassPropertyExW varptr(ClassGuid), varptr(PropertyKey), PropertyType, varptr(PropertyBuffer), PropertyBufferSize, Flags, MachineName, Reserved   ; 戻り値は stat
; ClassGuid : GUID* -> "sptr"
; PropertyKey : DEVPROPKEY* -> "sptr"
; PropertyType : DEVPROPTYPE -> "sptr"
; PropertyBuffer : BYTE* optional -> "sptr"
; PropertyBufferSize : DWORD -> "sptr"
; Flags : DWORD -> "sptr"
; MachineName : LPCWSTR optional -> "sptr"
; Reserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetClassPropertyExW "SetupDiSetClassPropertyExW" var, var, int, var, int, int, wstr, sptr
; res = SetupDiSetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags, MachineName, Reserved)
; ClassGuid : GUID* -> "var"
; PropertyKey : DEVPROPKEY* -> "var"
; PropertyType : DEVPROPTYPE -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; Flags : DWORD -> "int"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiSetClassPropertyExW(GUID* ClassGuid, DEVPROPKEY* PropertyKey, DEVPROPTYPE PropertyType, BYTE* PropertyBuffer, DWORD PropertyBufferSize, DWORD Flags, LPCWSTR MachineName, void* Reserved)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiSetClassPropertyExW "SetupDiSetClassPropertyExW" var, var, int, var, int, int, wstr, intptr
; res = SetupDiSetClassPropertyExW(ClassGuid, PropertyKey, PropertyType, PropertyBuffer, PropertyBufferSize, Flags, MachineName, Reserved)
; ClassGuid : GUID* -> "var"
; PropertyKey : DEVPROPKEY* -> "var"
; PropertyType : DEVPROPTYPE -> "int"
; PropertyBuffer : BYTE* optional -> "var"
; PropertyBufferSize : DWORD -> "int"
; Flags : 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")
	procSetupDiSetClassPropertyExW = setupapi.NewProc("SetupDiSetClassPropertyExW")
)

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

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

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

let setupdisetclasspropertyexw =
  foreign "SetupDiSetClassPropertyExW"
    ((ptr void) @-> (ptr void) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> 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 *)
(* 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 ("SetupDiSetClassPropertyExW" setup-di-set-class-property-ex-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
  (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 $SetupDiSetClassPropertyExW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiSetClassPropertyExW(LPVOID ClassGuid, LPVOID PropertyKey, DWORD PropertyType, LPVOID PropertyBuffer, DWORD PropertyBufferSize, DWORD Flags, LPCWSTR MachineName, LPVOID Reserved)');
# my $ret = $SetupDiSetClassPropertyExW->Call($ClassGuid, $PropertyKey, $PropertyType, $PropertyBuffer, $PropertyBufferSize, $Flags, $MachineName, $Reserved);
# ClassGuid : GUID* -> LPVOID
# PropertyKey : DEVPROPKEY* -> LPVOID
# PropertyType : DEVPROPTYPE -> DWORD
# PropertyBuffer : BYTE* optional -> LPVOID
# PropertyBufferSize : DWORD -> DWORD
# Flags : DWORD -> DWORD
# MachineName : LPCWSTR optional -> LPCWSTR
# Reserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型