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

SetupDiInstallClassW

関数
INFファイルからデバイスセットアップクラスをインストールする。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiInstallClassW(
    HWND hwndParent,   // optional
    LPCWSTR InfFileName,
    DWORD Flags,
    void* FileQueue   // optional
);

パラメーター

名前方向
hwndParentHWNDinoptional
InfFileNameLPCWSTRin
FlagsDWORDin
FileQueuevoid*inoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiInstallClassW = setupapi.NewProc("SetupDiInstallClassW")
)

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