SetupDiBuildDriverInfoList
関数シグネチャ
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiBuildDriverInfoList(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData, // optional
SETUP_DI_DRIVER_TYPE DriverType
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| DeviceInfoSet | HDEVINFO | in | ドライバー一覧を格納する デバイス情報セット へのハンドル。一覧は、すべてのデバイス情報要素に対してグローバルに、または単一のデバイス情報要素に対して個別に格納されます。デバイス情報セットに、リモートのデバイス情報要素が含まれていてはなりません。 | ||||||
| DeviceInfoData | SP_DEVINFO_DATA* | inoutoptional | ドライバー一覧を構築する対象のデバイスを表す、DeviceInfoSet 内のデバイス情報要素の SP_DEVINFO_DATA 構造体へのポインター。このパラメーターは省略可能で、NULL を指定できます。このパラメーターを指定した場合、一覧は指定したデバイスに関連付けられます。このパラメーターが NULL の場合、一覧は DeviceInfoSet のグローバルクラスドライバー一覧に関連付けられます。 互換ドライバー一覧の構築によってこのデバイスのクラスが更新された場合、DeviceInfoData.ClassGuid は戻り時に更新されます。 | ||||||
| DriverType | SETUP_DI_DRIVER_TYPE | in | 構築するドライバー一覧の種類。次のいずれかの値を指定する必要があります。
|
戻り値の型: BOOL
公式ドキュメント
SetupDiBuildDriverInfoList 関数は、特定のデバイスに関連付けられたドライバーの一覧、またはデバイス情報セットのグローバルクラスドライバー一覧を構築します。
戻り値
この関数は、成功した場合に TRUE を返します。それ以外の場合は FALSE を返し、記録されたエラーは GetLastError を呼び出すことで取得できます。
解説(Remarks)
SetupDiBuildDriverInfoList はローカルコンピューター上のドライバーのみを検索するため、デバイス情報セットはローカルコンピューターのものである必要があります。デバイス情報セットがリモートコンピューターのものである場合、この関数は TRUE を返しますが、デバイス情報セットの既存のドライバー一覧、および指定されている場合はデバイス情報要素のドライバー一覧を実際には更新しません。
呼び出し元は、デバイス情報セットまたは特定のデバイス (DeviceInfoData) に関連付けられた SP_DEVINSTALL_PARAMS の Flags を設定して、一覧の構築方法を制御できます。たとえば、呼び出し元が DI_FLAGSEX_ALLOWEXCLUDEDDRVS フラグを設定すると、Exclude From Select としてマークされたドライバーも含められます。
ドライバーが "Exclude From Select" となるのは、INF ファイル内で ExcludeFromSelect としてマークされている場合、または、そのデバイスのセットアップクラス全体がクラスインストーラーの INF ファイル内で NoInstallClass もしくは NoUseClass としてマークされているデバイス用のドライバーである場合です。PnP デバイス用のドライバーは通常 "Exclude From Select" です。PnP デバイスは手動でインストールすべきではありません。PnP デバイス用のドライバーファイルの一覧を構築するには、SetupDiBuildDriverInfoList の呼び出し元はこのフラグを設定する必要があります。
SP_DEVINSTALL_PARAMS の DriverPath には、INF ファイルを含むディレクトリのパス、または特定の INF ファイルのパスのいずれかが格納されます。DI_ENUMSINGLEINF が設定されている場合、DriverPath には単一の INF ファイルのパスが格納されます。DriverPath が NULL の場合、この関数は既定の INF ファイルの場所である %SystemRoot%\inf からドライバー一覧を構築します。
この関数が指定されたドライバー一覧を構築した後、呼び出し元は SetupDiEnumDriverInfo を呼び出すことで一覧のエントリを列挙できます。
ドライバー一覧がデバイスインスタンスに関連付けられている場合 (つまり DeviceInfoData が指定されている場合)、生成される一覧は、関連付けられたデバイスインスタンスと同じクラスを持つドライバーで構成されます。グローバルクラスドライバー一覧の場合 (つまり DriverType が SPDIT_CLASSDRIVER で、DeviceInfoData が指定されていない場合)、一覧の構築時に使用されるクラスは、デバイス情報セットに関連付けられたクラスです。デバイス情報セットに関連付けられたクラスがない場合は、一覧の構築時にすべてのクラスのドライバーが使用されます。
別のスレッドから SetupDiCancelDriverInfoSearch を呼び出すことで、ドライバー一覧の構築を終了させることができます。
DeviceInfoSet には、ローカルコンピューター上の要素のみが含まれている必要があります。この関数はローカルのドライバーのみを検索します。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiBuildDriverInfoList(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData, // optional
SETUP_DI_DRIVER_TYPE DriverType
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiBuildDriverInfoList(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData, // SP_DEVINFO_DATA* optional, in/out
uint DriverType // SETUP_DI_DRIVER_TYPE
);<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiBuildDriverInfoList(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr, ' SP_DEVINFO_DATA* optional, in/out
DriverType As UInteger ' SETUP_DI_DRIVER_TYPE
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
' DriverType : SETUP_DI_DRIVER_TYPE
Declare PtrSafe Function SetupDiBuildDriverInfoList Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr, _
ByVal DriverType As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiBuildDriverInfoList = ctypes.windll.setupapi.SetupDiBuildDriverInfoList
SetupDiBuildDriverInfoList.restype = wintypes.BOOL
SetupDiBuildDriverInfoList.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
wintypes.DWORD, # DriverType : SETUP_DI_DRIVER_TYPE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiBuildDriverInfoList = Fiddle::Function.new(
lib['SetupDiBuildDriverInfoList'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
-Fiddle::TYPE_INT, # DriverType : SETUP_DI_DRIVER_TYPE
],
Fiddle::TYPE_INT)#[link(name = "setupapi")]
extern "system" {
fn SetupDiBuildDriverInfoList(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA, // SP_DEVINFO_DATA* optional, in/out
DriverType: u32 // SETUP_DI_DRIVER_TYPE
) -> 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 SetupDiBuildDriverInfoList(IntPtr DeviceInfoSet, IntPtr DeviceInfoData, uint DriverType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiBuildDriverInfoList' -Namespace Win32 -PassThru
# $api::SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType)#uselib "SETUPAPI.dll"
#func global SetupDiBuildDriverInfoList "SetupDiBuildDriverInfoList" sptr, sptr, sptr
; SetupDiBuildDriverInfoList DeviceInfoSet, varptr(DeviceInfoData), DriverType ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr"
; DriverType : SETUP_DI_DRIVER_TYPE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll" #cfunc global SetupDiBuildDriverInfoList "SetupDiBuildDriverInfoList" sptr, var, int ; res = SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var" ; DriverType : SETUP_DI_DRIVER_TYPE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiBuildDriverInfoList "SetupDiBuildDriverInfoList" sptr, sptr, int ; res = SetupDiBuildDriverInfoList(DeviceInfoSet, varptr(DeviceInfoData), DriverType) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr" ; DriverType : SETUP_DI_DRIVER_TYPE -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL SetupDiBuildDriverInfoList(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SETUP_DI_DRIVER_TYPE DriverType) #uselib "SETUPAPI.dll" #cfunc global SetupDiBuildDriverInfoList "SetupDiBuildDriverInfoList" intptr, var, int ; res = SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var" ; DriverType : SETUP_DI_DRIVER_TYPE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiBuildDriverInfoList(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData, SETUP_DI_DRIVER_TYPE DriverType) #uselib "SETUPAPI.dll" #cfunc global SetupDiBuildDriverInfoList "SetupDiBuildDriverInfoList" intptr, intptr, int ; res = SetupDiBuildDriverInfoList(DeviceInfoSet, varptr(DeviceInfoData), DriverType) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "intptr" ; DriverType : SETUP_DI_DRIVER_TYPE -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiBuildDriverInfoList = setupapi.NewProc("SetupDiBuildDriverInfoList")
)
// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA* optional, in/out), DriverType (SETUP_DI_DRIVER_TYPE)
r1, _, err := procSetupDiBuildDriverInfoList.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
uintptr(DriverType),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiBuildDriverInfoList(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA* optional, in/out
DriverType: DWORD // SETUP_DI_DRIVER_TYPE
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiBuildDriverInfoList';result := DllCall("SETUPAPI\SetupDiBuildDriverInfoList"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA* optional, in/out
, "UInt", DriverType ; SETUP_DI_DRIVER_TYPE
, "Int") ; return: BOOL●SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType) = DLL("SETUPAPI.dll", "bool SetupDiBuildDriverInfoList(int, void*, dword)")
# 呼び出し: SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "void*"
# DriverType : SETUP_DI_DRIVER_TYPE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "setupapi" fn SetupDiBuildDriverInfoList(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: [*c]SP_DEVINFO_DATA, // SP_DEVINFO_DATA* optional, in/out
DriverType: u32 // SETUP_DI_DRIVER_TYPE
) callconv(std.os.windows.WINAPI) i32;proc SetupDiBuildDriverInfoList(
DeviceInfoSet: int, # HDEVINFO
DeviceInfoData: ptr SP_DEVINFO_DATA, # SP_DEVINFO_DATA* optional, in/out
DriverType: uint32 # SETUP_DI_DRIVER_TYPE
): int32 {.importc: "SetupDiBuildDriverInfoList", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupDiBuildDriverInfoList(
ptrdiff_t DeviceInfoSet, // HDEVINFO
SP_DEVINFO_DATA* DeviceInfoData, // SP_DEVINFO_DATA* optional, in/out
uint DriverType // SETUP_DI_DRIVER_TYPE
);ccall((:SetupDiBuildDriverInfoList, "SETUPAPI.dll"), stdcall, Int32,
(Int, Ptr{SP_DEVINFO_DATA}, UInt32),
DeviceInfoSet, DeviceInfoData, DriverType)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> Ptr{SP_DEVINFO_DATA}
# DriverType : SETUP_DI_DRIVER_TYPE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiBuildDriverInfoList(
intptr_t DeviceInfoSet,
void* DeviceInfoData,
uint32_t DriverType);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType)
-- DeviceInfoSet : HDEVINFO
-- DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
-- DriverType : SETUP_DI_DRIVER_TYPE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiBuildDriverInfoList = lib.func('__stdcall', 'SetupDiBuildDriverInfoList', 'int32_t', ['intptr_t', 'void *', 'uint32_t']);
// SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> 'void *'
// DriverType : SETUP_DI_DRIVER_TYPE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupDiBuildDriverInfoList: { parameters: ["isize", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "pointer"
// DriverType : SETUP_DI_DRIVER_TYPE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiBuildDriverInfoList(
intptr_t DeviceInfoSet,
void* DeviceInfoData,
uint32_t DriverType);
C, "SETUPAPI.dll");
// $ffi->SetupDiBuildDriverInfoList(DeviceInfoSet, DeviceInfoData, DriverType);
// DeviceInfoSet : HDEVINFO
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
// DriverType : SETUP_DI_DRIVER_TYPE
// 構造体/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);
boolean SetupDiBuildDriverInfoList(
long DeviceInfoSet, // HDEVINFO
Pointer DeviceInfoData, // SP_DEVINFO_DATA* optional, in/out
int DriverType // SETUP_DI_DRIVER_TYPE
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupDiBuildDriverInfoList = SetupDiBuildDriverInfoList(
DeviceInfoSet : LibC::SSizeT, # HDEVINFO
DeviceInfoData : SP_DEVINFO_DATA*, # SP_DEVINFO_DATA* optional, in/out
DriverType : UInt32 # SETUP_DI_DRIVER_TYPE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupDiBuildDriverInfoListNative = Int32 Function(IntPtr, Pointer<Void>, Uint32);
typedef SetupDiBuildDriverInfoListDart = int Function(int, Pointer<Void>, int);
final SetupDiBuildDriverInfoList = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiBuildDriverInfoListNative, SetupDiBuildDriverInfoListDart>('SetupDiBuildDriverInfoList');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> Pointer<Void>
// DriverType : SETUP_DI_DRIVER_TYPE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupDiBuildDriverInfoList(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer; // SP_DEVINFO_DATA* optional, in/out
DriverType: DWORD // SETUP_DI_DRIVER_TYPE
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiBuildDriverInfoList';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiBuildDriverInfoList"
c_SetupDiBuildDriverInfoList :: CIntPtr -> Ptr () -> Word32 -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> Ptr ()
-- DriverType : SETUP_DI_DRIVER_TYPE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupdibuilddriverinfolist =
foreign "SetupDiBuildDriverInfoList"
(intptr_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> (ptr void) *)
(* DriverType : SETUP_DI_DRIVER_TYPE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupDiBuildDriverInfoList" setup-di-build-driver-info-list :convention :stdcall) :int32
(device-info-set :int64) ; HDEVINFO
(device-info-data :pointer) ; SP_DEVINFO_DATA* optional, in/out
(driver-type :uint32)) ; SETUP_DI_DRIVER_TYPE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupDiBuildDriverInfoList = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiBuildDriverInfoList(LPARAM DeviceInfoSet, LPVOID DeviceInfoData, DWORD DriverType)');
# my $ret = $SetupDiBuildDriverInfoList->Call($DeviceInfoSet, $DeviceInfoData, $DriverType);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> LPVOID
# DriverType : SETUP_DI_DRIVER_TYPE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f SetupDiCancelDriverInfoSearch — 進行中のドライバ情報の検索を取り消す。
- f SetupDiDestroyDriverInfoList — デバイスのドライバ情報リストを破棄し解放する。
- f SetupDiEnumDriverInfoW — ドライバ情報リスト内のドライバを順に列挙する。