ホーム › Devices.DeviceAndDriverInstallation › SetupGetInfInformationW
SetupGetInfInformationW
関数INFファイルの情報をSP_INF_INFORMATION構造体に取得する(Unicode)。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupGetInfInformationW(
const void* InfSpec,
DWORD SearchControl,
SP_INF_INFORMATION* ReturnBuffer, // optional
DWORD ReturnBufferSize,
DWORD* RequiredSize // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InfSpec | void* | in | 対象INFを示す指定。INFハンドル、ファイル名、ファイルグループ名のいずれかをSearchControlに応じて渡す。 |
| SearchControl | DWORD | in | InfSpecの解釈方法を示す制御フラグ。INFSPEC種別を指定する。 |
| ReturnBuffer | SP_INF_INFORMATION* | outoptional | INF情報を受け取るSP_INF_INFORMATION構造体へのバッファ。NULLでサイズ取得のみ可。 |
| ReturnBufferSize | DWORD | in | ReturnBufferのサイズ(バイト単位)。 |
| RequiredSize | DWORD* | outoptional | 実際に必要なバッファサイズ(バイト単位)を受け取る出力ポインタ。NULL可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupGetInfInformationW(
const void* InfSpec,
DWORD SearchControl,
SP_INF_INFORMATION* ReturnBuffer, // optional
DWORD ReturnBufferSize,
DWORD* RequiredSize // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupGetInfInformationW(
IntPtr InfSpec, // void*
uint SearchControl, // DWORD
IntPtr ReturnBuffer, // SP_INF_INFORMATION* optional, out
uint ReturnBufferSize, // DWORD
IntPtr RequiredSize // DWORD* optional, out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupGetInfInformationW(
InfSpec As IntPtr, ' void*
SearchControl As UInteger, ' DWORD
ReturnBuffer As IntPtr, ' SP_INF_INFORMATION* optional, out
ReturnBufferSize As UInteger, ' DWORD
RequiredSize As IntPtr ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' InfSpec : void*
' SearchControl : DWORD
' ReturnBuffer : SP_INF_INFORMATION* optional, out
' ReturnBufferSize : DWORD
' RequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupGetInfInformationW Lib "setupapi" ( _
ByVal InfSpec As LongPtr, _
ByVal SearchControl As Long, _
ByVal ReturnBuffer As LongPtr, _
ByVal ReturnBufferSize As Long, _
ByVal RequiredSize 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
SetupGetInfInformationW = ctypes.windll.setupapi.SetupGetInfInformationW
SetupGetInfInformationW.restype = wintypes.BOOL
SetupGetInfInformationW.argtypes = [
ctypes.POINTER(None), # InfSpec : void*
wintypes.DWORD, # SearchControl : DWORD
ctypes.c_void_p, # ReturnBuffer : SP_INF_INFORMATION* optional, out
wintypes.DWORD, # ReturnBufferSize : DWORD
ctypes.POINTER(wintypes.DWORD), # RequiredSize : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupGetInfInformationW = Fiddle::Function.new(
lib['SetupGetInfInformationW'],
[
Fiddle::TYPE_VOIDP, # InfSpec : void*
-Fiddle::TYPE_INT, # SearchControl : DWORD
Fiddle::TYPE_VOIDP, # ReturnBuffer : SP_INF_INFORMATION* optional, out
-Fiddle::TYPE_INT, # ReturnBufferSize : DWORD
Fiddle::TYPE_VOIDP, # RequiredSize : DWORD* optional, out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupGetInfInformationW(
InfSpec: *const (), // void*
SearchControl: u32, // DWORD
ReturnBuffer: *mut SP_INF_INFORMATION, // SP_INF_INFORMATION* optional, out
ReturnBufferSize: u32, // DWORD
RequiredSize: *mut u32 // DWORD* optional, out
) -> 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 SetupGetInfInformationW(IntPtr InfSpec, uint SearchControl, IntPtr ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetInfInformationW' -Namespace Win32 -PassThru
# $api::SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize)#uselib "SETUPAPI.dll"
#func global SetupGetInfInformationW "SetupGetInfInformationW" wptr, wptr, wptr, wptr, wptr
; SetupGetInfInformationW InfSpec, SearchControl, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize) ; 戻り値は stat
; InfSpec : void* -> "wptr"
; SearchControl : DWORD -> "wptr"
; ReturnBuffer : SP_INF_INFORMATION* optional, out -> "wptr"
; ReturnBufferSize : DWORD -> "wptr"
; RequiredSize : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupGetInfInformationW "SetupGetInfInformationW" sptr, int, var, int, var ; res = SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize) ; InfSpec : void* -> "sptr" ; SearchControl : DWORD -> "int" ; ReturnBuffer : SP_INF_INFORMATION* optional, out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupGetInfInformationW "SetupGetInfInformationW" sptr, int, sptr, int, sptr ; res = SetupGetInfInformationW(InfSpec, SearchControl, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; InfSpec : void* -> "sptr" ; SearchControl : DWORD -> "int" ; ReturnBuffer : SP_INF_INFORMATION* optional, out -> "sptr" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupGetInfInformationW(void* InfSpec, DWORD SearchControl, SP_INF_INFORMATION* ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetInfInformationW "SetupGetInfInformationW" intptr, int, var, int, var ; res = SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize) ; InfSpec : void* -> "intptr" ; SearchControl : DWORD -> "int" ; ReturnBuffer : SP_INF_INFORMATION* optional, out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupGetInfInformationW(void* InfSpec, DWORD SearchControl, SP_INF_INFORMATION* ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetInfInformationW "SetupGetInfInformationW" intptr, int, intptr, int, intptr ; res = SetupGetInfInformationW(InfSpec, SearchControl, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; InfSpec : void* -> "intptr" ; SearchControl : DWORD -> "int" ; ReturnBuffer : SP_INF_INFORMATION* optional, out -> "intptr" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupGetInfInformationW = setupapi.NewProc("SetupGetInfInformationW")
)
// InfSpec (void*), SearchControl (DWORD), ReturnBuffer (SP_INF_INFORMATION* optional, out), ReturnBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupGetInfInformationW.Call(
uintptr(InfSpec),
uintptr(SearchControl),
uintptr(ReturnBuffer),
uintptr(ReturnBufferSize),
uintptr(RequiredSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupGetInfInformationW(
InfSpec: Pointer; // void*
SearchControl: DWORD; // DWORD
ReturnBuffer: Pointer; // SP_INF_INFORMATION* optional, out
ReturnBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetInfInformationW';result := DllCall("SETUPAPI\SetupGetInfInformationW"
, "Ptr", InfSpec ; void*
, "UInt", SearchControl ; DWORD
, "Ptr", ReturnBuffer ; SP_INF_INFORMATION* optional, out
, "UInt", ReturnBufferSize ; DWORD
, "Ptr", RequiredSize ; DWORD* optional, out
, "Int") ; return: BOOL●SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupGetInfInformationW(void*, dword, void*, dword, void*)")
# 呼び出し: SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize)
# InfSpec : void* -> "void*"
# SearchControl : DWORD -> "dword"
# ReturnBuffer : SP_INF_INFORMATION* optional, out -> "void*"
# ReturnBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupGetInfInformationW(
InfSpec: ?*anyopaque, // void*
SearchControl: u32, // DWORD
ReturnBuffer: [*c]SP_INF_INFORMATION, // SP_INF_INFORMATION* optional, out
ReturnBufferSize: u32, // DWORD
RequiredSize: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupGetInfInformationW(
InfSpec: pointer, # void*
SearchControl: uint32, # DWORD
ReturnBuffer: ptr SP_INF_INFORMATION, # SP_INF_INFORMATION* optional, out
ReturnBufferSize: uint32, # DWORD
RequiredSize: ptr uint32 # DWORD* optional, out
): int32 {.importc: "SetupGetInfInformationW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
int SetupGetInfInformationW(
void* InfSpec, // void*
uint SearchControl, // DWORD
SP_INF_INFORMATION* ReturnBuffer, // SP_INF_INFORMATION* optional, out
uint ReturnBufferSize, // DWORD
uint* RequiredSize // DWORD* optional, out
);ccall((:SetupGetInfInformationW, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Ptr{SP_INF_INFORMATION}, UInt32, Ptr{UInt32}),
InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize)
# InfSpec : void* -> Ptr{Cvoid}
# SearchControl : DWORD -> UInt32
# ReturnBuffer : SP_INF_INFORMATION* optional, out -> Ptr{SP_INF_INFORMATION}
# ReturnBufferSize : DWORD -> UInt32
# RequiredSize : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupGetInfInformationW(
void* InfSpec,
uint32_t SearchControl,
void* ReturnBuffer,
uint32_t ReturnBufferSize,
uint32_t* RequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize)
-- InfSpec : void*
-- SearchControl : DWORD
-- ReturnBuffer : SP_INF_INFORMATION* optional, out
-- ReturnBufferSize : DWORD
-- RequiredSize : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupGetInfInformationW = lib.func('__stdcall', 'SetupGetInfInformationW', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t', 'uint32_t *']);
// SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize)
// InfSpec : void* -> 'void *'
// SearchControl : DWORD -> 'uint32_t'
// ReturnBuffer : SP_INF_INFORMATION* optional, out -> 'void *'
// ReturnBufferSize : DWORD -> 'uint32_t'
// RequiredSize : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupGetInfInformationW: { parameters: ["pointer", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize)
// InfSpec : void* -> "pointer"
// SearchControl : DWORD -> "u32"
// ReturnBuffer : SP_INF_INFORMATION* optional, out -> "pointer"
// ReturnBufferSize : DWORD -> "u32"
// RequiredSize : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupGetInfInformationW(
void* InfSpec,
uint32_t SearchControl,
void* ReturnBuffer,
uint32_t ReturnBufferSize,
uint32_t* RequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupGetInfInformationW(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize);
// InfSpec : void*
// SearchControl : DWORD
// ReturnBuffer : SP_INF_INFORMATION* optional, out
// ReturnBufferSize : DWORD
// RequiredSize : DWORD* optional, out
// 構造体/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.UNICODE_OPTIONS);
boolean SetupGetInfInformationW(
Pointer InfSpec, // void*
int SearchControl, // DWORD
Pointer ReturnBuffer, // SP_INF_INFORMATION* optional, out
int ReturnBufferSize, // DWORD
IntByReference RequiredSize // DWORD* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupGetInfInformationW = SetupGetInfInformationW(
InfSpec : Void*, # void*
SearchControl : UInt32, # DWORD
ReturnBuffer : SP_INF_INFORMATION*, # SP_INF_INFORMATION* optional, out
ReturnBufferSize : UInt32, # DWORD
RequiredSize : UInt32* # DWORD* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupGetInfInformationWNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef SetupGetInfInformationWDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Uint32>);
final SetupGetInfInformationW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupGetInfInformationWNative, SetupGetInfInformationWDart>('SetupGetInfInformationW');
// InfSpec : void* -> Pointer<Void>
// SearchControl : DWORD -> Uint32
// ReturnBuffer : SP_INF_INFORMATION* optional, out -> Pointer<Void>
// ReturnBufferSize : DWORD -> Uint32
// RequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupGetInfInformationW(
InfSpec: Pointer; // void*
SearchControl: DWORD; // DWORD
ReturnBuffer: Pointer; // SP_INF_INFORMATION* optional, out
ReturnBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetInfInformationW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupGetInfInformationW"
c_SetupGetInfInformationW :: Ptr () -> Word32 -> Ptr () -> Word32 -> Ptr Word32 -> IO CInt
-- InfSpec : void* -> Ptr ()
-- SearchControl : DWORD -> Word32
-- ReturnBuffer : SP_INF_INFORMATION* optional, out -> Ptr ()
-- ReturnBufferSize : DWORD -> Word32
-- RequiredSize : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupgetinfinformationw =
foreign "SetupGetInfInformationW"
((ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* InfSpec : void* -> (ptr void) *)
(* SearchControl : DWORD -> uint32_t *)
(* ReturnBuffer : SP_INF_INFORMATION* optional, out -> (ptr void) *)
(* ReturnBufferSize : DWORD -> uint32_t *)
(* RequiredSize : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupGetInfInformationW" setup-get-inf-information-w :convention :stdcall) :int32
(inf-spec :pointer) ; void*
(search-control :uint32) ; DWORD
(return-buffer :pointer) ; SP_INF_INFORMATION* optional, out
(return-buffer-size :uint32) ; DWORD
(required-size :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupGetInfInformationW = Win32::API::More->new('SETUPAPI',
'BOOL SetupGetInfInformationW(LPVOID InfSpec, DWORD SearchControl, LPVOID ReturnBuffer, DWORD ReturnBufferSize, LPVOID RequiredSize)');
# my $ret = $SetupGetInfInformationW->Call($InfSpec, $SearchControl, $ReturnBuffer, $ReturnBufferSize, $RequiredSize);
# InfSpec : void* -> LPVOID
# SearchControl : DWORD -> DWORD
# ReturnBuffer : SP_INF_INFORMATION* optional, out -> LPVOID
# ReturnBufferSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetupGetInfInformationA (ANSI版) — INFファイルの情報をSP_INF_INFORMATION構造体に取得する(ANSI)。
使用する型