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

SetupDiCallClassInstaller

関数
デバイスのクラスインストーラに指定関数を呼び出させる。
DLLSETUPAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiCallClassInstaller(
    DI_FUNCTION InstallFunction,
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);

パラメーター

名前方向説明
InstallFunctionDI_FUNCTIONinクラスインストーラに渡すインストール要求。DIF_INSTALLDEVICE等のDI_FUNCTION値を指定する。
DeviceInfoSetHDEVINFOin対象のデバイス情報セットを指すハンドル。
DeviceInfoDataSP_DEVINFO_DATA*inoptional要求を適用する対象デバイスの構造体。NULL指定でセット全体に適用する。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiCallClassInstaller(
    DI_FUNCTION InstallFunction,
    HDEVINFO DeviceInfoSet,
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiCallClassInstaller(
    uint InstallFunction,   // DI_FUNCTION
    IntPtr DeviceInfoSet,   // HDEVINFO
    IntPtr DeviceInfoData   // SP_DEVINFO_DATA* optional
);
<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiCallClassInstaller(
    InstallFunction As UInteger,   ' DI_FUNCTION
    DeviceInfoSet As IntPtr,   ' HDEVINFO
    DeviceInfoData As IntPtr   ' SP_DEVINFO_DATA* optional
) As Boolean
End Function
' InstallFunction : DI_FUNCTION
' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA* optional
Declare PtrSafe Function SetupDiCallClassInstaller Lib "setupapi" ( _
    ByVal InstallFunction As Long, _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInfoData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiCallClassInstaller = ctypes.windll.setupapi.SetupDiCallClassInstaller
SetupDiCallClassInstaller.restype = wintypes.BOOL
SetupDiCallClassInstaller.argtypes = [
    wintypes.DWORD,  # InstallFunction : DI_FUNCTION
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiCallClassInstaller = Fiddle::Function.new(
  lib['SetupDiCallClassInstaller'],
  [
    -Fiddle::TYPE_INT,  # InstallFunction : DI_FUNCTION
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
    Fiddle::TYPE_VOIDP,  # DeviceInfoData : SP_DEVINFO_DATA* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiCallClassInstaller(
        InstallFunction: u32,  // DI_FUNCTION
        DeviceInfoSet: isize,  // HDEVINFO
        DeviceInfoData: *mut SP_DEVINFO_DATA  // SP_DEVINFO_DATA* 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 SetupDiCallClassInstaller(uint InstallFunction, IntPtr DeviceInfoSet, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiCallClassInstaller' -Namespace Win32 -PassThru
# $api::SetupDiCallClassInstaller(InstallFunction, DeviceInfoSet, DeviceInfoData)
#uselib "SETUPAPI.dll"
#func global SetupDiCallClassInstaller "SetupDiCallClassInstaller" sptr, sptr, sptr
; SetupDiCallClassInstaller InstallFunction, DeviceInfoSet, varptr(DeviceInfoData)   ; 戻り値は stat
; InstallFunction : DI_FUNCTION -> "sptr"
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiCallClassInstaller "SetupDiCallClassInstaller" int, sptr, var
; res = SetupDiCallClassInstaller(InstallFunction, DeviceInfoSet, DeviceInfoData)
; InstallFunction : DI_FUNCTION -> "int"
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiCallClassInstaller(DI_FUNCTION InstallFunction, HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiCallClassInstaller "SetupDiCallClassInstaller" int, intptr, var
; res = SetupDiCallClassInstaller(InstallFunction, DeviceInfoSet, DeviceInfoData)
; InstallFunction : DI_FUNCTION -> "int"
; DeviceInfoSet : HDEVINFO -> "intptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiCallClassInstaller = setupapi.NewProc("SetupDiCallClassInstaller")
)

// InstallFunction (DI_FUNCTION), DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA* optional)
r1, _, err := procSetupDiCallClassInstaller.Call(
	uintptr(InstallFunction),
	uintptr(DeviceInfoSet),
	uintptr(DeviceInfoData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiCallClassInstaller(
  InstallFunction: DWORD;   // DI_FUNCTION
  DeviceInfoSet: NativeInt;   // HDEVINFO
  DeviceInfoData: Pointer   // SP_DEVINFO_DATA* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiCallClassInstaller';
result := DllCall("SETUPAPI\SetupDiCallClassInstaller"
    , "UInt", InstallFunction   ; DI_FUNCTION
    , "Ptr", DeviceInfoSet   ; HDEVINFO
    , "Ptr", DeviceInfoData   ; SP_DEVINFO_DATA* optional
    , "Int")   ; return: BOOL
●SetupDiCallClassInstaller(InstallFunction, DeviceInfoSet, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupDiCallClassInstaller(dword, int, void*)")
# 呼び出し: SetupDiCallClassInstaller(InstallFunction, DeviceInfoSet, DeviceInfoData)
# InstallFunction : DI_FUNCTION -> "dword"
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。