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

SetupDiInstallClassExW

関数
インターフェイスクラス対応でセットアップクラスを導入する。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiInstallClassExW(
    HWND hwndParent,   // optional
    LPCWSTR InfFileName,   // optional
    DWORD Flags,
    void* FileQueue,   // optional
    const GUID* InterfaceClassGuid,   // optional
    void* Reserved1,   // optional
    void* Reserved2   // optional
);

パラメーター

名前方向
hwndParentHWNDinoptional
InfFileNameLPCWSTRinoptional
FlagsDWORDin
FileQueuevoid*inoptional
InterfaceClassGuidGUID*inoptional
Reserved1void*optional
Reserved2void*optional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiInstallClassExW(
    HWND hwndParent,   // optional
    LPCWSTR InfFileName,   // optional
    DWORD Flags,
    void* FileQueue,   // optional
    const GUID* InterfaceClassGuid,   // optional
    void* Reserved1,   // optional
    void* Reserved2   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiInstallClassExW(
    IntPtr hwndParent,   // HWND optional
    [MarshalAs(UnmanagedType.LPWStr)] string InfFileName,   // LPCWSTR optional
    uint Flags,   // DWORD
    IntPtr FileQueue,   // void* optional
    IntPtr InterfaceClassGuid,   // GUID* optional
    IntPtr Reserved1,   // void* optional
    IntPtr Reserved2   // void* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiInstallClassExW(
    hwndParent As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPWStr)> InfFileName As String,   ' LPCWSTR optional
    Flags As UInteger,   ' DWORD
    FileQueue As IntPtr,   ' void* optional
    InterfaceClassGuid As IntPtr,   ' GUID* optional
    Reserved1 As IntPtr,   ' void* optional
    Reserved2 As IntPtr   ' void* optional
) As Boolean
End Function
' hwndParent : HWND optional
' InfFileName : LPCWSTR optional
' Flags : DWORD
' FileQueue : void* optional
' InterfaceClassGuid : GUID* optional
' Reserved1 : void* optional
' Reserved2 : void* optional
Declare PtrSafe Function SetupDiInstallClassExW Lib "setupapi" ( _
    ByVal hwndParent As LongPtr, _
    ByVal InfFileName As LongPtr, _
    ByVal Flags As Long, _
    ByVal FileQueue As LongPtr, _
    ByVal InterfaceClassGuid As LongPtr, _
    ByVal Reserved1 As LongPtr, _
    ByVal Reserved2 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

SetupDiInstallClassExW = ctypes.windll.setupapi.SetupDiInstallClassExW
SetupDiInstallClassExW.restype = wintypes.BOOL
SetupDiInstallClassExW.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND optional
    wintypes.LPCWSTR,  # InfFileName : LPCWSTR optional
    wintypes.DWORD,  # Flags : DWORD
    ctypes.POINTER(None),  # FileQueue : void* optional
    ctypes.c_void_p,  # InterfaceClassGuid : GUID* optional
    ctypes.POINTER(None),  # Reserved1 : void* optional
    ctypes.POINTER(None),  # Reserved2 : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiInstallClassExW = Fiddle::Function.new(
  lib['SetupDiInstallClassExW'],
  [
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # InfFileName : LPCWSTR optional
    -Fiddle::TYPE_INT,  # Flags : DWORD
    Fiddle::TYPE_VOIDP,  # FileQueue : void* optional
    Fiddle::TYPE_VOIDP,  # InterfaceClassGuid : GUID* optional
    Fiddle::TYPE_VOIDP,  # Reserved1 : void* optional
    Fiddle::TYPE_VOIDP,  # Reserved2 : void* optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiInstallClassExW(
        hwndParent: *mut core::ffi::c_void,  // HWND optional
        InfFileName: *const u16,  // LPCWSTR optional
        Flags: u32,  // DWORD
        FileQueue: *mut (),  // void* optional
        InterfaceClassGuid: *const GUID,  // GUID* optional
        Reserved1: *mut (),  // void* optional
        Reserved2: *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 SetupDiInstallClassExW(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string InfFileName, uint Flags, IntPtr FileQueue, IntPtr InterfaceClassGuid, IntPtr Reserved1, IntPtr Reserved2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiInstallClassExW' -Namespace Win32 -PassThru
# $api::SetupDiInstallClassExW(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
#uselib "SETUPAPI.dll"
#func global SetupDiInstallClassExW "SetupDiInstallClassExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiInstallClassExW hwndParent, InfFileName, Flags, FileQueue, varptr(InterfaceClassGuid), Reserved1, Reserved2   ; 戻り値は stat
; hwndParent : HWND optional -> "wptr"
; InfFileName : LPCWSTR optional -> "wptr"
; Flags : DWORD -> "wptr"
; FileQueue : void* optional -> "wptr"
; InterfaceClassGuid : GUID* optional -> "wptr"
; Reserved1 : void* optional -> "wptr"
; Reserved2 : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiInstallClassExW "SetupDiInstallClassExW" sptr, wstr, int, sptr, var, sptr, sptr
; res = SetupDiInstallClassExW(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
; hwndParent : HWND optional -> "sptr"
; InfFileName : LPCWSTR optional -> "wstr"
; Flags : DWORD -> "int"
; FileQueue : void* optional -> "sptr"
; InterfaceClassGuid : GUID* optional -> "var"
; Reserved1 : void* optional -> "sptr"
; Reserved2 : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiInstallClassExW(HWND hwndParent, LPCWSTR InfFileName, DWORD Flags, void* FileQueue, GUID* InterfaceClassGuid, void* Reserved1, void* Reserved2)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiInstallClassExW "SetupDiInstallClassExW" intptr, wstr, int, intptr, var, intptr, intptr
; res = SetupDiInstallClassExW(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
; hwndParent : HWND optional -> "intptr"
; InfFileName : LPCWSTR optional -> "wstr"
; Flags : DWORD -> "int"
; FileQueue : void* optional -> "intptr"
; InterfaceClassGuid : GUID* optional -> "var"
; Reserved1 : void* optional -> "intptr"
; Reserved2 : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiInstallClassExW = setupapi.NewProc("SetupDiInstallClassExW")
)

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