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

SetupDiInstallClassExA

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

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

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

パラメーター

名前方向説明
hwndParentHWNDinoptionalUI表示時の親ウィンドウハンドル。不要ならNULLを指定する。
InfFileNameLPCSTRinoptionalクラスをインストールするINFファイルのフルパス(ANSI)。インターフェイスのみ登録時はNULL可。
FlagsDWORDinインストール制御フラグ。DI_NOVCP等を指定する。
FileQueuevoid*inoptionalDI_NOVCP指定時に使うファイルキューハンドル。それ以外はNULL。
InterfaceClassGuidGUID*inoptional登録するインターフェイスクラスのGUID。セットアップクラス登録時はNULLを指定する。
Reserved1void*optional予約済み。NULLを指定する。
Reserved2void*optional予約済み。NULLを指定する。

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupDiInstallClassExA(
    HWND hwndParent,   // optional
    LPCSTR 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.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiInstallClassExA(
    IntPtr hwndParent,   // HWND optional
    [MarshalAs(UnmanagedType.LPStr)] string InfFileName,   // LPCSTR 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.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiInstallClassExA(
    hwndParent As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPStr)> InfFileName As String,   ' LPCSTR 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 <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hwndParent : HWND optional
' InfFileName : LPCSTR optional
' Flags : DWORD
' FileQueue : void* optional
' InterfaceClassGuid : GUID* optional
' Reserved1 : void* optional
' Reserved2 : void* optional
Declare PtrSafe Function SetupDiInstallClassExA Lib "setupapi" ( _
    ByVal hwndParent As LongPtr, _
    ByVal InfFileName As String, _
    ByVal Flags As Long, _
    ByVal FileQueue As LongPtr, _
    ByVal InterfaceClassGuid As LongPtr, _
    ByVal Reserved1 As LongPtr, _
    ByVal Reserved2 As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiInstallClassExA = ctypes.windll.setupapi.SetupDiInstallClassExA
SetupDiInstallClassExA.restype = wintypes.BOOL
SetupDiInstallClassExA.argtypes = [
    wintypes.HANDLE,  # hwndParent : HWND optional
    wintypes.LPCSTR,  # InfFileName : LPCSTR 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')
SetupDiInstallClassExA = Fiddle::Function.new(
  lib['SetupDiInstallClassExA'],
  [
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # InfFileName : LPCSTR 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)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiInstallClassExA(
        hwndParent: *mut core::ffi::c_void,  // HWND optional
        InfFileName: *const u8,  // LPCSTR 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.Ansi, SetLastError = true)]
public static extern bool SetupDiInstallClassExA(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPStr)] string InfFileName, uint Flags, IntPtr FileQueue, IntPtr InterfaceClassGuid, IntPtr Reserved1, IntPtr Reserved2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiInstallClassExA' -Namespace Win32 -PassThru
# $api::SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
#uselib "SETUPAPI.dll"
#func global SetupDiInstallClassExA "SetupDiInstallClassExA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiInstallClassExA hwndParent, InfFileName, Flags, FileQueue, varptr(InterfaceClassGuid), Reserved1, Reserved2   ; 戻り値は stat
; hwndParent : HWND optional -> "sptr"
; InfFileName : LPCSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; FileQueue : void* optional -> "sptr"
; InterfaceClassGuid : GUID* optional -> "sptr"
; Reserved1 : void* optional -> "sptr"
; Reserved2 : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiInstallClassExA "SetupDiInstallClassExA" sptr, str, int, sptr, var, sptr, sptr
; res = SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
; hwndParent : HWND optional -> "sptr"
; InfFileName : LPCSTR optional -> "str"
; Flags : DWORD -> "int"
; FileQueue : void* optional -> "sptr"
; InterfaceClassGuid : GUID* optional -> "var"
; Reserved1 : void* optional -> "sptr"
; Reserved2 : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiInstallClassExA(HWND hwndParent, LPCSTR InfFileName, DWORD Flags, void* FileQueue, GUID* InterfaceClassGuid, void* Reserved1, void* Reserved2)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiInstallClassExA "SetupDiInstallClassExA" intptr, str, int, intptr, var, intptr, intptr
; res = SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
; hwndParent : HWND optional -> "intptr"
; InfFileName : LPCSTR optional -> "str"
; 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")
	procSetupDiInstallClassExA = setupapi.NewProc("SetupDiInstallClassExA")
)

// hwndParent (HWND optional), InfFileName (LPCSTR optional), Flags (DWORD), FileQueue (void* optional), InterfaceClassGuid (GUID* optional), Reserved1 (void* optional), Reserved2 (void* optional)
r1, _, err := procSetupDiInstallClassExA.Call(
	uintptr(hwndParent),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(InfFileName))),
	uintptr(Flags),
	uintptr(FileQueue),
	uintptr(InterfaceClassGuid),
	uintptr(Reserved1),
	uintptr(Reserved2),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiInstallClassExA(
  hwndParent: THandle;   // HWND optional
  InfFileName: PAnsiChar;   // LPCSTR 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 'SetupDiInstallClassExA';
result := DllCall("SETUPAPI\SetupDiInstallClassExA"
    , "Ptr", hwndParent   ; HWND optional
    , "AStr", InfFileName   ; LPCSTR optional
    , "UInt", Flags   ; DWORD
    , "Ptr", FileQueue   ; void* optional
    , "Ptr", InterfaceClassGuid   ; GUID* optional
    , "Ptr", Reserved1   ; void* optional
    , "Ptr", Reserved2   ; void* optional
    , "Int")   ; return: BOOL
●SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2) = DLL("SETUPAPI.dll", "bool SetupDiInstallClassExA(void*, char*, dword, void*, void*, void*, void*)")
# 呼び出し: SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
# hwndParent : HWND optional -> "void*"
# InfFileName : LPCSTR 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)。
const std = @import("std");

extern "setupapi" fn SetupDiInstallClassExA(
    hwndParent: ?*anyopaque, // HWND optional
    InfFileName: [*c]const u8, // LPCSTR optional
    Flags: u32, // DWORD
    FileQueue: ?*anyopaque, // void* optional
    InterfaceClassGuid: [*c]GUID, // GUID* optional
    Reserved1: ?*anyopaque, // void* optional
    Reserved2: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
proc SetupDiInstallClassExA(
    hwndParent: pointer,  # HWND optional
    InfFileName: cstring,  # LPCSTR optional
    Flags: uint32,  # DWORD
    FileQueue: pointer,  # void* optional
    InterfaceClassGuid: ptr GUID,  # GUID* optional
    Reserved1: pointer,  # void* optional
    Reserved2: pointer  # void* optional
): int32 {.importc: "SetupDiInstallClassExA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupDiInstallClassExA(
    void* hwndParent,   // HWND optional
    const(char)* InfFileName,   // LPCSTR optional
    uint Flags,   // DWORD
    void* FileQueue,   // void* optional
    GUID* InterfaceClassGuid,   // GUID* optional
    void* Reserved1,   // void* optional
    void* Reserved2   // void* optional
);
ccall((:SetupDiInstallClassExA, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cstring, UInt32, Ptr{Cvoid}, Ptr{GUID}, Ptr{Cvoid}, Ptr{Cvoid}),
      hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
# hwndParent : HWND optional -> Ptr{Cvoid}
# InfFileName : LPCSTR optional -> Cstring
# Flags : DWORD -> UInt32
# FileQueue : void* optional -> Ptr{Cvoid}
# InterfaceClassGuid : GUID* optional -> Ptr{GUID}
# Reserved1 : void* optional -> Ptr{Cvoid}
# Reserved2 : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiInstallClassExA(
    void* hwndParent,
    const char* InfFileName,
    uint32_t Flags,
    void* FileQueue,
    void* InterfaceClassGuid,
    void* Reserved1,
    void* Reserved2);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
-- hwndParent : HWND optional
-- InfFileName : LPCSTR optional
-- Flags : DWORD
-- FileQueue : void* optional
-- InterfaceClassGuid : GUID* optional
-- Reserved1 : void* optional
-- Reserved2 : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiInstallClassExA = lib.func('__stdcall', 'SetupDiInstallClassExA', 'int32_t', ['void *', 'str', 'uint32_t', 'void *', 'void *', 'void *', 'void *']);
// SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
// hwndParent : HWND optional -> 'void *'
// InfFileName : LPCSTR optional -> 'str'
// Flags : DWORD -> 'uint32_t'
// FileQueue : void* optional -> 'void *'
// InterfaceClassGuid : GUID* optional -> 'void *'
// Reserved1 : void* optional -> 'void *'
// Reserved2 : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiInstallClassExA: { parameters: ["pointer", "buffer", "u32", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2)
// hwndParent : HWND optional -> "pointer"
// InfFileName : LPCSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// FileQueue : void* optional -> "pointer"
// InterfaceClassGuid : GUID* optional -> "pointer"
// Reserved1 : void* optional -> "pointer"
// Reserved2 : void* optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiInstallClassExA(
    void* hwndParent,
    const char* InfFileName,
    uint32_t Flags,
    void* FileQueue,
    void* InterfaceClassGuid,
    void* Reserved1,
    void* Reserved2);
C, "SETUPAPI.dll");
// $ffi->SetupDiInstallClassExA(hwndParent, InfFileName, Flags, FileQueue, InterfaceClassGuid, Reserved1, Reserved2);
// hwndParent : HWND optional
// InfFileName : LPCSTR optional
// Flags : DWORD
// FileQueue : void* optional
// InterfaceClassGuid : GUID* optional
// Reserved1 : void* optional
// Reserved2 : 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, W32APIOptions.ASCII_OPTIONS);
    boolean SetupDiInstallClassExA(
        Pointer hwndParent,   // HWND optional
        String InfFileName,   // LPCSTR optional
        int Flags,   // DWORD
        Pointer FileQueue,   // void* optional
        Pointer InterfaceClassGuid,   // GUID* optional
        Pointer Reserved1,   // void* optional
        Pointer Reserved2   // void* optional
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiInstallClassExA = SetupDiInstallClassExA(
    hwndParent : Void*,   # HWND optional
    InfFileName : UInt8*,   # LPCSTR optional
    Flags : UInt32,   # DWORD
    FileQueue : Void*,   # void* optional
    InterfaceClassGuid : GUID*,   # GUID* optional
    Reserved1 : Void*,   # void* optional
    Reserved2 : 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 SetupDiInstallClassExANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef SetupDiInstallClassExADart = int Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final SetupDiInstallClassExA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiInstallClassExANative, SetupDiInstallClassExADart>('SetupDiInstallClassExA');
// hwndParent : HWND optional -> Pointer<Void>
// InfFileName : LPCSTR optional -> Pointer<Utf8>
// Flags : DWORD -> Uint32
// FileQueue : void* optional -> Pointer<Void>
// InterfaceClassGuid : GUID* optional -> Pointer<Void>
// Reserved1 : void* optional -> Pointer<Void>
// Reserved2 : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupDiInstallClassExA(
  hwndParent: THandle;   // HWND optional
  InfFileName: PAnsiChar;   // LPCSTR 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 'SetupDiInstallClassExA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiInstallClassExA"
  c_SetupDiInstallClassExA :: Ptr () -> CString -> Word32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO CInt
-- hwndParent : HWND optional -> Ptr ()
-- InfFileName : LPCSTR optional -> CString
-- Flags : DWORD -> Word32
-- FileQueue : void* optional -> Ptr ()
-- InterfaceClassGuid : GUID* optional -> Ptr ()
-- Reserved1 : void* optional -> Ptr ()
-- Reserved2 : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdiinstallclassexa =
  foreign "SetupDiInstallClassExA"
    ((ptr void) @-> string @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* InfFileName : LPCSTR optional -> string *)
(* Flags : DWORD -> uint32_t *)
(* FileQueue : void* optional -> (ptr void) *)
(* InterfaceClassGuid : GUID* optional -> (ptr void) *)
(* Reserved1 : void* optional -> (ptr void) *)
(* Reserved2 : 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 ("SetupDiInstallClassExA" setup-di-install-class-ex-a :convention :stdcall) :int32
  (hwnd-parent :pointer)   ; HWND optional
  (inf-file-name :string)   ; LPCSTR optional
  (flags :uint32)   ; DWORD
  (file-queue :pointer)   ; void* optional
  (interface-class-guid :pointer)   ; GUID* optional
  (reserved1 :pointer)   ; void* optional
  (reserved2 :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiInstallClassExA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiInstallClassExA(HANDLE hwndParent, LPCSTR InfFileName, DWORD Flags, LPVOID FileQueue, LPVOID InterfaceClassGuid, LPVOID Reserved1, LPVOID Reserved2)');
# my $ret = $SetupDiInstallClassExA->Call($hwndParent, $InfFileName, $Flags, $FileQueue, $InterfaceClassGuid, $Reserved1, $Reserved2);
# hwndParent : HWND optional -> HANDLE
# InfFileName : LPCSTR optional -> LPCSTR
# Flags : DWORD -> DWORD
# FileQueue : void* optional -> LPVOID
# InterfaceClassGuid : GUID* optional -> LPVOID
# Reserved1 : void* optional -> LPVOID
# Reserved2 : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
類似 API