ホーム › Devices.DeviceAndDriverInstallation › SetupDiInstallClassA
SetupDiInstallClassA
関数INFファイルからデバイスセットアップクラスをインストールする。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiInstallClassA(
HWND hwndParent, // optional
LPCSTR InfFileName,
DWORD Flags,
void* FileQueue // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwndParent | HWND | inoptional | UI表示時の親ウィンドウハンドル。不要ならNULLを指定する。 |
| InfFileName | LPCSTR | in | クラスをインストールするINFファイルのフルパス(ANSI)。 |
| Flags | DWORD | in | インストール制御フラグ。DI_NOVCP(ファイルコピー抑制)やDI_FORCECOPY等を指定する。 |
| FileQueue | void* | inoptional | DI_NOVCP指定時に使うファイルキューハンドル。それ以外はNULLを指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiInstallClassA(
HWND hwndParent, // optional
LPCSTR InfFileName,
DWORD Flags,
void* FileQueue // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiInstallClassA(
IntPtr hwndParent, // HWND optional
[MarshalAs(UnmanagedType.LPStr)] string InfFileName, // LPCSTR
uint Flags, // DWORD
IntPtr FileQueue // void* optional
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiInstallClassA(
hwndParent As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPStr)> InfFileName As String, ' LPCSTR
Flags As UInteger, ' DWORD
FileQueue As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hwndParent : HWND optional
' InfFileName : LPCSTR
' Flags : DWORD
' FileQueue : void* optional
Declare PtrSafe Function SetupDiInstallClassA Lib "setupapi" ( _
ByVal hwndParent As LongPtr, _
ByVal InfFileName As String, _
ByVal Flags As Long, _
ByVal FileQueue As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiInstallClassA = ctypes.windll.setupapi.SetupDiInstallClassA
SetupDiInstallClassA.restype = wintypes.BOOL
SetupDiInstallClassA.argtypes = [
wintypes.HANDLE, # hwndParent : HWND optional
wintypes.LPCSTR, # InfFileName : LPCSTR
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')
SetupDiInstallClassA = Fiddle::Function.new(
lib['SetupDiInstallClassA'],
[
Fiddle::TYPE_VOIDP, # hwndParent : HWND optional
Fiddle::TYPE_VOIDP, # InfFileName : LPCSTR
-Fiddle::TYPE_INT, # Flags : DWORD
Fiddle::TYPE_VOIDP, # FileQueue : void* optional
],
Fiddle::TYPE_INT)#[link(name = "setupapi")]
extern "system" {
fn SetupDiInstallClassA(
hwndParent: *mut core::ffi::c_void, // HWND optional
InfFileName: *const u8, // LPCSTR
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.Ansi, SetLastError = true)]
public static extern bool SetupDiInstallClassA(IntPtr hwndParent, [MarshalAs(UnmanagedType.LPStr)] string InfFileName, uint Flags, IntPtr FileQueue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiInstallClassA' -Namespace Win32 -PassThru
# $api::SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue)#uselib "SETUPAPI.dll"
#func global SetupDiInstallClassA "SetupDiInstallClassA" sptr, sptr, sptr, sptr
; SetupDiInstallClassA hwndParent, InfFileName, Flags, FileQueue ; 戻り値は stat
; hwndParent : HWND optional -> "sptr"
; InfFileName : LPCSTR -> "sptr"
; Flags : DWORD -> "sptr"
; FileQueue : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll"
#cfunc global SetupDiInstallClassA "SetupDiInstallClassA" sptr, str, int, sptr
; res = SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue)
; hwndParent : HWND optional -> "sptr"
; InfFileName : LPCSTR -> "str"
; Flags : DWORD -> "int"
; FileQueue : void* optional -> "sptr"; BOOL SetupDiInstallClassA(HWND hwndParent, LPCSTR InfFileName, DWORD Flags, void* FileQueue)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiInstallClassA "SetupDiInstallClassA" intptr, str, int, intptr
; res = SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue)
; hwndParent : HWND optional -> "intptr"
; InfFileName : LPCSTR -> "str"
; Flags : DWORD -> "int"
; FileQueue : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiInstallClassA = setupapi.NewProc("SetupDiInstallClassA")
)
// hwndParent (HWND optional), InfFileName (LPCSTR), Flags (DWORD), FileQueue (void* optional)
r1, _, err := procSetupDiInstallClassA.Call(
uintptr(hwndParent),
uintptr(unsafe.Pointer(windows.BytePtrFromString(InfFileName))),
uintptr(Flags),
uintptr(FileQueue),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiInstallClassA(
hwndParent: THandle; // HWND optional
InfFileName: PAnsiChar; // LPCSTR
Flags: DWORD; // DWORD
FileQueue: Pointer // void* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiInstallClassA';result := DllCall("SETUPAPI\SetupDiInstallClassA"
, "Ptr", hwndParent ; HWND optional
, "AStr", InfFileName ; LPCSTR
, "UInt", Flags ; DWORD
, "Ptr", FileQueue ; void* optional
, "Int") ; return: BOOL●SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue) = DLL("SETUPAPI.dll", "bool SetupDiInstallClassA(void*, char*, dword, void*)")
# 呼び出し: SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue)
# hwndParent : HWND optional -> "void*"
# InfFileName : LPCSTR -> "char*"
# Flags : DWORD -> "dword"
# FileQueue : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "setupapi" fn SetupDiInstallClassA(
hwndParent: ?*anyopaque, // HWND optional
InfFileName: [*c]const u8, // LPCSTR
Flags: u32, // DWORD
FileQueue: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc SetupDiInstallClassA(
hwndParent: pointer, # HWND optional
InfFileName: cstring, # LPCSTR
Flags: uint32, # DWORD
FileQueue: pointer # void* optional
): int32 {.importc: "SetupDiInstallClassA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupDiInstallClassA(
void* hwndParent, // HWND optional
const(char)* InfFileName, // LPCSTR
uint Flags, // DWORD
void* FileQueue // void* optional
);ccall((:SetupDiInstallClassA, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cstring, UInt32, Ptr{Cvoid}),
hwndParent, InfFileName, Flags, FileQueue)
# hwndParent : HWND optional -> Ptr{Cvoid}
# InfFileName : LPCSTR -> Cstring
# Flags : DWORD -> UInt32
# FileQueue : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiInstallClassA(
void* hwndParent,
const char* InfFileName,
uint32_t Flags,
void* FileQueue);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue)
-- hwndParent : HWND optional
-- InfFileName : LPCSTR
-- Flags : DWORD
-- FileQueue : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiInstallClassA = lib.func('__stdcall', 'SetupDiInstallClassA', 'int32_t', ['void *', 'str', 'uint32_t', 'void *']);
// SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue)
// hwndParent : HWND optional -> 'void *'
// InfFileName : LPCSTR -> 'str'
// Flags : DWORD -> 'uint32_t'
// FileQueue : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupDiInstallClassA: { parameters: ["pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue)
// hwndParent : HWND optional -> "pointer"
// InfFileName : LPCSTR -> "buffer"
// Flags : DWORD -> "u32"
// FileQueue : void* optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiInstallClassA(
void* hwndParent,
const char* InfFileName,
uint32_t Flags,
void* FileQueue);
C, "SETUPAPI.dll");
// $ffi->SetupDiInstallClassA(hwndParent, InfFileName, Flags, FileQueue);
// hwndParent : HWND optional
// InfFileName : LPCSTR
// Flags : DWORD
// FileQueue : 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 SetupDiInstallClassA(
Pointer hwndParent, // HWND optional
String InfFileName, // LPCSTR
int Flags, // DWORD
Pointer FileQueue // void* optional
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupDiInstallClassA = SetupDiInstallClassA(
hwndParent : Void*, # HWND optional
InfFileName : UInt8*, # LPCSTR
Flags : UInt32, # DWORD
FileQueue : 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 SetupDiInstallClassANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Void>);
typedef SetupDiInstallClassADart = int Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Void>);
final SetupDiInstallClassA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiInstallClassANative, SetupDiInstallClassADart>('SetupDiInstallClassA');
// hwndParent : HWND optional -> Pointer<Void>
// InfFileName : LPCSTR -> Pointer<Utf8>
// Flags : DWORD -> Uint32
// FileQueue : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupDiInstallClassA(
hwndParent: THandle; // HWND optional
InfFileName: PAnsiChar; // LPCSTR
Flags: DWORD; // DWORD
FileQueue: Pointer // void* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiInstallClassA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiInstallClassA"
c_SetupDiInstallClassA :: Ptr () -> CString -> Word32 -> Ptr () -> IO CInt
-- hwndParent : HWND optional -> Ptr ()
-- InfFileName : LPCSTR -> CString
-- Flags : DWORD -> Word32
-- FileQueue : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupdiinstallclassa =
foreign "SetupDiInstallClassA"
((ptr void) @-> string @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hwndParent : HWND optional -> (ptr void) *)
(* InfFileName : LPCSTR -> string *)
(* Flags : DWORD -> uint32_t *)
(* FileQueue : 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 ("SetupDiInstallClassA" setup-di-install-class-a :convention :stdcall) :int32
(hwnd-parent :pointer) ; HWND optional
(inf-file-name :string) ; LPCSTR
(flags :uint32) ; DWORD
(file-queue :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupDiInstallClassA = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiInstallClassA(HANDLE hwndParent, LPCSTR InfFileName, DWORD Flags, LPVOID FileQueue)');
# my $ret = $SetupDiInstallClassA->Call($hwndParent, $InfFileName, $Flags, $FileQueue);
# hwndParent : HWND optional -> HANDLE
# InfFileName : LPCSTR -> LPCSTR
# Flags : DWORD -> DWORD
# FileQueue : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupDiInstallClassW (Unicode版) — INFファイルからデバイスセットアップクラスをインストールする。
類似 API
- f SetupDiInstallClassExA — インターフェイスクラス対応でセットアップクラスを導入する。