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

SetupGetInfInformationA

関数
INFファイルの情報をSP_INF_INFORMATION構造体に取得する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupGetInfInformationA(
    const void* InfSpec,
    DWORD SearchControl,
    SP_INF_INFORMATION* ReturnBuffer,   // optional
    DWORD ReturnBufferSize,
    DWORD* RequiredSize   // optional
);

パラメーター

名前方向説明
InfSpecvoid*in対象INFを示す指定。INFハンドル、ファイル名、ファイルグループ名のいずれかをSearchControlに応じて渡す。
SearchControlDWORDinInfSpecの解釈方法を示す制御フラグ。INFSPEC種別を指定する。
ReturnBufferSP_INF_INFORMATION*outoptionalINF情報を受け取るSP_INF_INFORMATION構造体へのバッファ。NULLでサイズ取得のみ可。
ReturnBufferSizeDWORDinReturnBufferのサイズ(バイト単位)。
RequiredSizeDWORD*outoptional実際に必要なバッファサイズ(バイト単位)を受け取る出力ポインタ。NULL可。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupGetInfInformationA(
    const void* InfSpec,
    DWORD SearchControl,
    SP_INF_INFORMATION* ReturnBuffer,   // optional
    DWORD ReturnBufferSize,
    DWORD* RequiredSize   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupGetInfInformationA(
    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.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupGetInfInformationA(
    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 SetupGetInfInformationA Lib "setupapi" ( _
    ByVal InfSpec As LongPtr, _
    ByVal SearchControl As Long, _
    ByVal ReturnBuffer As LongPtr, _
    ByVal ReturnBufferSize As Long, _
    ByVal RequiredSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupGetInfInformationA = ctypes.windll.setupapi.SetupGetInfInformationA
SetupGetInfInformationA.restype = wintypes.BOOL
SetupGetInfInformationA.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')
SetupGetInfInformationA = Fiddle::Function.new(
  lib['SetupGetInfInformationA'],
  [
    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)
#[link(name = "setupapi")]
extern "system" {
    fn SetupGetInfInformationA(
        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.Ansi, SetLastError = true)]
public static extern bool SetupGetInfInformationA(IntPtr InfSpec, uint SearchControl, IntPtr ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetInfInformationA' -Namespace Win32 -PassThru
# $api::SetupGetInfInformationA(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize)
#uselib "SETUPAPI.dll"
#func global SetupGetInfInformationA "SetupGetInfInformationA" sptr, sptr, sptr, sptr, sptr
; SetupGetInfInformationA InfSpec, SearchControl, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)   ; 戻り値は stat
; InfSpec : void* -> "sptr"
; SearchControl : DWORD -> "sptr"
; ReturnBuffer : SP_INF_INFORMATION* optional, out -> "sptr"
; ReturnBufferSize : DWORD -> "sptr"
; RequiredSize : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupGetInfInformationA "SetupGetInfInformationA" sptr, int, var, int, var
; res = SetupGetInfInformationA(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 方式にも切替可。
出力引数:
; BOOL SetupGetInfInformationA(void* InfSpec, DWORD SearchControl, SP_INF_INFORMATION* ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupGetInfInformationA "SetupGetInfInformationA" intptr, int, var, int, var
; res = SetupGetInfInformationA(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 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupGetInfInformationA = setupapi.NewProc("SetupGetInfInformationA")
)

// InfSpec (void*), SearchControl (DWORD), ReturnBuffer (SP_INF_INFORMATION* optional, out), ReturnBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupGetInfInformationA.Call(
	uintptr(InfSpec),
	uintptr(SearchControl),
	uintptr(ReturnBuffer),
	uintptr(ReturnBufferSize),
	uintptr(RequiredSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupGetInfInformationA(
  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 'SetupGetInfInformationA';
result := DllCall("SETUPAPI\SetupGetInfInformationA"
    , "Ptr", InfSpec   ; void*
    , "UInt", SearchControl   ; DWORD
    , "Ptr", ReturnBuffer   ; SP_INF_INFORMATION* optional, out
    , "UInt", ReturnBufferSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●SetupGetInfInformationA(InfSpec, SearchControl, ReturnBuffer, ReturnBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupGetInfInformationA(void*, dword, void*, dword, void*)")
# 呼び出し: SetupGetInfInformationA(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)。
const std = @import("std");

extern "setupapi" fn SetupGetInfInformationA(
    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;
proc SetupGetInfInformationA(
    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: "SetupGetInfInformationA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupGetInfInformationA(
    void* InfSpec,   // void*
    uint SearchControl,   // DWORD
    SP_INF_INFORMATION* ReturnBuffer,   // SP_INF_INFORMATION* optional, out
    uint ReturnBufferSize,   // DWORD
    uint* RequiredSize   // DWORD* optional, out
);
ccall((:SetupGetInfInformationA, "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 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupGetInfInformationA(
    void* InfSpec,
    uint32_t SearchControl,
    void* ReturnBuffer,
    uint32_t ReturnBufferSize,
    uint32_t* RequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetInfInformationA(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 に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupGetInfInformationA = lib.func('__stdcall', 'SetupGetInfInformationA', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t', 'uint32_t *']);
// SetupGetInfInformationA(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", {
  SetupGetInfInformationA: { parameters: ["pointer", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupGetInfInformationA(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"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupGetInfInformationA(
    void* InfSpec,
    uint32_t SearchControl,
    void* ReturnBuffer,
    uint32_t ReturnBufferSize,
    uint32_t* RequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupGetInfInformationA(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.ASCII_OPTIONS);
    boolean SetupGetInfInformationA(
        Pointer InfSpec,   // void*
        int SearchControl,   // DWORD
        Pointer ReturnBuffer,   // SP_INF_INFORMATION* optional, out
        int ReturnBufferSize,   // DWORD
        IntByReference RequiredSize   // DWORD* optional, out
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupGetInfInformationA = SetupGetInfInformationA(
    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 SetupGetInfInformationANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef SetupGetInfInformationADart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Uint32>);
final SetupGetInfInformationA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupGetInfInformationANative, SetupGetInfInformationADart>('SetupGetInfInformationA');
// 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 SetupGetInfInformationA(
  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 'SetupGetInfInformationA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupGetInfInformationA"
  c_SetupGetInfInformationA :: 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 setupgetinfinformationa =
  foreign "SetupGetInfInformationA"
    ((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 ("SetupGetInfInformationA" setup-get-inf-information-a :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 $SetupGetInfInformationA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupGetInfInformationA(LPVOID InfSpec, DWORD SearchControl, LPVOID ReturnBuffer, DWORD ReturnBufferSize, LPVOID RequiredSize)');
# my $ret = $SetupGetInfInformationA->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 を使用。

関連項目

文字セット違い
使用する型