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

SetupQueryInfVersionInformationA

関数
INFのバージョン情報セクションから指定キーの値を取得する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupQueryInfVersionInformationA(
    SP_INF_INFORMATION* InfInformation,
    DWORD InfIndex,
    LPCSTR Key,   // optional
    LPSTR ReturnBuffer,   // optional
    DWORD ReturnBufferSize,
    DWORD* RequiredSize   // optional
);

パラメーター

名前方向説明
InfInformationSP_INF_INFORMATION*inSP_INF_INFORMATION 構造体へのポインター。この構造体は、 SetupGetInfInformation 関数の呼び出しによって以前に返されたものです。
InfIndexDWORDinバージョン情報を取得する構成 INF ファイルのインデックス。このインデックスは [0, InfInformation.InfCount) の範囲を指定できます。つまり、0 から InfInformation.InfCount の直前までの値が有効です。
KeyLPCSTRinoptional取得する文字列に対応付けられたキー名を含む null 終端文字列への、省略可能なポインター。このパラメーターが NULL の場合、すべてのリソースキーが指定されたバッファーにコピーされます。各文字列は null 終端であり、リストの末尾にはさらに null が 1 つ付加されます。
ReturnBufferLPSTRoutoptionalNULL でない場合、ReturnBuffer は、この関数が INF ファイルのスタイルを返す、呼び出し側が用意した文字バッファーを指します。null 終端文字列を使用してください。null 終端文字列は、コピー先バッファーのサイズを超えてはなりません。関数を一度呼び出して必要なバッファーサイズを取得し、必要なメモリを割り当ててから、2 回目の呼び出しでデータを取得できます。この手法により、バッファーサイズの不足によるエラーを回避できます。「解説」セクションを参照してください。このパラメーターは NULL にできます。
ReturnBufferSizeDWORDinReturnBuffer パラメーターが指すバッファーのサイズ (文字数単位)。この数には null 終端文字が含まれます。
RequiredSizeDWORD*outoptionalNULL でない場合、ReturnBuffer パラメーターが指すバッファーに必要なサイズ (文字数単位) を受け取る変数へのポインター。この数には null 終端文字が含まれます。ReturnBuffer が指定されており、実際のサイズが ReturnBufferSize で指定された値より大きい場合、関数は失敗し、 GetLastError を呼び出すと ERROR_INSUFFICIENT_BUFFER が返されます。

戻り値の型: BOOL

公式ドキュメント

SetupQueryInfVersionInformation 関数は、SP_INF_INFORMATION 構造体から INF ファイルのバージョン情報をバッファーに返します。(ANSI)

戻り値

関数が成功した場合、戻り値は 0 以外の値です。

関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

この関数を ReturnBufferNULLReturnBufferSize に 0 を指定して呼び出した場合、関数は、指定されたデータを格納するために必要なバッファーサイズを RequiredSize が指す変数に格納します。これに成功した場合、戻り値は 0 以外の値です。それ以外の場合、戻り値は 0 であり、GetLastError を呼び出すことで拡張エラー情報を取得できます。

SetupQueryInfVersionInformation をレガシー INF ファイルに対して呼び出した場合、バージョン情報は次のようにレガシー INF ファイルから生成されます。

  1. レガシーファイルの Identification セクションにある OptionType キーが、Class キーの値として返されます。
  2. レガシー INF ファイルの Signature セクションにある FileType キーが、Signature キーの値になります。
  3. レガシー INF ファイルの FileType キーの値が MICROSOFT_FILE の場合、Provider キーの値は "Microsoft" に設定されます。
次の表は、情報が SP_INF_INFORMATION 構造体に渡される前に、どのように変換されるかをまとめたものです。
レガシーファイルの情報 Windows INF の情報
[Identification]
OptionType = Mouse
[Version]
Class=Mouse
[Signature]
FileType = MICROSOFT_FILE
Signature=MICROSOFT_FILE
(FileType が MICROSOFT_FILE の場合)
Provider="Microsoft"
メモ

setupapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版と Unicode 版を自動的に選択するエイリアスとして SetupQueryInfVersionInformation を定義します。エンコーディングに中立なこのエイリアスの使用を、エンコーディングに中立でないコードと混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となる場合があります。詳細については、「Conventions for Function Prototypes」を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL SetupQueryInfVersionInformationA(
    SP_INF_INFORMATION* InfInformation,
    DWORD InfIndex,
    LPCSTR Key,   // optional
    LPSTR ReturnBuffer,   // optional
    DWORD ReturnBufferSize,
    DWORD* RequiredSize   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupQueryInfVersionInformationA(
    IntPtr InfInformation,   // SP_INF_INFORMATION*
    uint InfIndex,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string Key,   // LPCSTR optional
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder ReturnBuffer,   // LPSTR optional, out
    uint ReturnBufferSize,   // DWORD
    IntPtr RequiredSize   // DWORD* optional, out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupQueryInfVersionInformationA(
    InfInformation As IntPtr,   ' SP_INF_INFORMATION*
    InfIndex As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> Key As String,   ' LPCSTR optional
    <MarshalAs(UnmanagedType.LPStr)> ReturnBuffer As System.Text.StringBuilder,   ' LPSTR optional, out
    ReturnBufferSize As UInteger,   ' DWORD
    RequiredSize As IntPtr   ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' InfInformation : SP_INF_INFORMATION*
' InfIndex : DWORD
' Key : LPCSTR optional
' ReturnBuffer : LPSTR optional, out
' ReturnBufferSize : DWORD
' RequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupQueryInfVersionInformationA Lib "setupapi" ( _
    ByVal InfInformation As LongPtr, _
    ByVal InfIndex As Long, _
    ByVal Key As String, _
    ByVal ReturnBuffer As String, _
    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

SetupQueryInfVersionInformationA = ctypes.windll.setupapi.SetupQueryInfVersionInformationA
SetupQueryInfVersionInformationA.restype = wintypes.BOOL
SetupQueryInfVersionInformationA.argtypes = [
    ctypes.c_void_p,  # InfInformation : SP_INF_INFORMATION*
    wintypes.DWORD,  # InfIndex : DWORD
    wintypes.LPCSTR,  # Key : LPCSTR optional
    wintypes.LPSTR,  # ReturnBuffer : LPSTR 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')
SetupQueryInfVersionInformationA = Fiddle::Function.new(
  lib['SetupQueryInfVersionInformationA'],
  [
    Fiddle::TYPE_VOIDP,  # InfInformation : SP_INF_INFORMATION*
    -Fiddle::TYPE_INT,  # InfIndex : DWORD
    Fiddle::TYPE_VOIDP,  # Key : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # ReturnBuffer : LPSTR optional, out
    -Fiddle::TYPE_INT,  # ReturnBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredSize : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupQueryInfVersionInformationA(
        InfInformation: *mut SP_INF_INFORMATION,  // SP_INF_INFORMATION*
        InfIndex: u32,  // DWORD
        Key: *const u8,  // LPCSTR optional
        ReturnBuffer: *mut u8,  // LPSTR 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 SetupQueryInfVersionInformationA(IntPtr InfInformation, uint InfIndex, [MarshalAs(UnmanagedType.LPStr)] string Key, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupQueryInfVersionInformationA' -Namespace Win32 -PassThru
# $api::SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
#uselib "SETUPAPI.dll"
#func global SetupQueryInfVersionInformationA "SetupQueryInfVersionInformationA" sptr, sptr, sptr, sptr, sptr, sptr
; SetupQueryInfVersionInformationA varptr(InfInformation), InfIndex, Key, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)   ; 戻り値は stat
; InfInformation : SP_INF_INFORMATION* -> "sptr"
; InfIndex : DWORD -> "sptr"
; Key : LPCSTR optional -> "sptr"
; ReturnBuffer : LPSTR optional, out -> "sptr"
; ReturnBufferSize : DWORD -> "sptr"
; RequiredSize : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupQueryInfVersionInformationA "SetupQueryInfVersionInformationA" var, int, str, var, int, var
; res = SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
; InfInformation : SP_INF_INFORMATION* -> "var"
; InfIndex : DWORD -> "int"
; Key : LPCSTR optional -> "str"
; ReturnBuffer : LPSTR optional, out -> "var"
; ReturnBufferSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupQueryInfVersionInformationA(SP_INF_INFORMATION* InfInformation, DWORD InfIndex, LPCSTR Key, LPSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupQueryInfVersionInformationA "SetupQueryInfVersionInformationA" var, int, str, var, int, var
; res = SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
; InfInformation : SP_INF_INFORMATION* -> "var"
; InfIndex : DWORD -> "int"
; Key : LPCSTR optional -> "str"
; ReturnBuffer : LPSTR 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")
	procSetupQueryInfVersionInformationA = setupapi.NewProc("SetupQueryInfVersionInformationA")
)

// InfInformation (SP_INF_INFORMATION*), InfIndex (DWORD), Key (LPCSTR optional), ReturnBuffer (LPSTR optional, out), ReturnBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupQueryInfVersionInformationA.Call(
	uintptr(InfInformation),
	uintptr(InfIndex),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(Key))),
	uintptr(ReturnBuffer),
	uintptr(ReturnBufferSize),
	uintptr(RequiredSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupQueryInfVersionInformationA(
  InfInformation: Pointer;   // SP_INF_INFORMATION*
  InfIndex: DWORD;   // DWORD
  Key: PAnsiChar;   // LPCSTR optional
  ReturnBuffer: PAnsiChar;   // LPSTR optional, out
  ReturnBufferSize: DWORD;   // DWORD
  RequiredSize: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupQueryInfVersionInformationA';
result := DllCall("SETUPAPI\SetupQueryInfVersionInformationA"
    , "Ptr", InfInformation   ; SP_INF_INFORMATION*
    , "UInt", InfIndex   ; DWORD
    , "AStr", Key   ; LPCSTR optional
    , "Ptr", ReturnBuffer   ; LPSTR optional, out
    , "UInt", ReturnBufferSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupQueryInfVersionInformationA(void*, dword, char*, char*, dword, void*)")
# 呼び出し: SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
# InfInformation : SP_INF_INFORMATION* -> "void*"
# InfIndex : DWORD -> "dword"
# Key : LPCSTR optional -> "char*"
# ReturnBuffer : LPSTR optional, out -> "char*"
# ReturnBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupQueryInfVersionInformationA(
    InfInformation: [*c]SP_INF_INFORMATION, // SP_INF_INFORMATION*
    InfIndex: u32, // DWORD
    Key: [*c]const u8, // LPCSTR optional
    ReturnBuffer: [*c]u8, // LPSTR optional, out
    ReturnBufferSize: u32, // DWORD
    RequiredSize: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc SetupQueryInfVersionInformationA(
    InfInformation: ptr SP_INF_INFORMATION,  # SP_INF_INFORMATION*
    InfIndex: uint32,  # DWORD
    Key: cstring,  # LPCSTR optional
    ReturnBuffer: ptr char,  # LPSTR optional, out
    ReturnBufferSize: uint32,  # DWORD
    RequiredSize: ptr uint32  # DWORD* optional, out
): int32 {.importc: "SetupQueryInfVersionInformationA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupQueryInfVersionInformationA(
    SP_INF_INFORMATION* InfInformation,   // SP_INF_INFORMATION*
    uint InfIndex,   // DWORD
    const(char)* Key,   // LPCSTR optional
    char* ReturnBuffer,   // LPSTR optional, out
    uint ReturnBufferSize,   // DWORD
    uint* RequiredSize   // DWORD* optional, out
);
ccall((:SetupQueryInfVersionInformationA, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{SP_INF_INFORMATION}, UInt32, Cstring, Ptr{UInt8}, UInt32, Ptr{UInt32}),
      InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
# InfInformation : SP_INF_INFORMATION* -> Ptr{SP_INF_INFORMATION}
# InfIndex : DWORD -> UInt32
# Key : LPCSTR optional -> Cstring
# ReturnBuffer : LPSTR optional, out -> Ptr{UInt8}
# ReturnBufferSize : DWORD -> UInt32
# RequiredSize : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupQueryInfVersionInformationA(
    void* InfInformation,
    uint32_t InfIndex,
    const char* Key,
    char* ReturnBuffer,
    uint32_t ReturnBufferSize,
    uint32_t* RequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
-- InfInformation : SP_INF_INFORMATION*
-- InfIndex : DWORD
-- Key : LPCSTR optional
-- ReturnBuffer : LPSTR 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 SetupQueryInfVersionInformationA = lib.func('__stdcall', 'SetupQueryInfVersionInformationA', 'int32_t', ['void *', 'uint32_t', 'str', 'char *', 'uint32_t', 'uint32_t *']);
// SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
// InfInformation : SP_INF_INFORMATION* -> 'void *'
// InfIndex : DWORD -> 'uint32_t'
// Key : LPCSTR optional -> 'str'
// ReturnBuffer : LPSTR optional, out -> 'char *'
// ReturnBufferSize : DWORD -> 'uint32_t'
// RequiredSize : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupQueryInfVersionInformationA: { parameters: ["pointer", "u32", "buffer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
// InfInformation : SP_INF_INFORMATION* -> "pointer"
// InfIndex : DWORD -> "u32"
// Key : LPCSTR optional -> "buffer"
// ReturnBuffer : LPSTR optional, out -> "buffer"
// 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 SetupQueryInfVersionInformationA(
    void* InfInformation,
    uint32_t InfIndex,
    const char* Key,
    char* ReturnBuffer,
    uint32_t ReturnBufferSize,
    uint32_t* RequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupQueryInfVersionInformationA(InfInformation, InfIndex, Key, ReturnBuffer, ReturnBufferSize, RequiredSize);
// InfInformation : SP_INF_INFORMATION*
// InfIndex : DWORD
// Key : LPCSTR optional
// ReturnBuffer : LPSTR 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 SetupQueryInfVersionInformationA(
        Pointer InfInformation,   // SP_INF_INFORMATION*
        int InfIndex,   // DWORD
        String Key,   // LPCSTR optional
        byte[] ReturnBuffer,   // LPSTR optional, out
        int ReturnBufferSize,   // DWORD
        IntByReference RequiredSize   // DWORD* optional, out
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupQueryInfVersionInformationA = SetupQueryInfVersionInformationA(
    InfInformation : SP_INF_INFORMATION*,   # SP_INF_INFORMATION*
    InfIndex : UInt32,   # DWORD
    Key : UInt8*,   # LPCSTR optional
    ReturnBuffer : UInt8*,   # LPSTR 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 SetupQueryInfVersionInformationANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Uint32>);
typedef SetupQueryInfVersionInformationADart = int Function(Pointer<Void>, int, Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Uint32>);
final SetupQueryInfVersionInformationA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupQueryInfVersionInformationANative, SetupQueryInfVersionInformationADart>('SetupQueryInfVersionInformationA');
// InfInformation : SP_INF_INFORMATION* -> Pointer<Void>
// InfIndex : DWORD -> Uint32
// Key : LPCSTR optional -> Pointer<Utf8>
// ReturnBuffer : LPSTR optional, out -> Pointer<Utf8>
// ReturnBufferSize : DWORD -> Uint32
// RequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupQueryInfVersionInformationA(
  InfInformation: Pointer;   // SP_INF_INFORMATION*
  InfIndex: DWORD;   // DWORD
  Key: PAnsiChar;   // LPCSTR optional
  ReturnBuffer: PAnsiChar;   // LPSTR optional, out
  ReturnBufferSize: DWORD;   // DWORD
  RequiredSize: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupQueryInfVersionInformationA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupQueryInfVersionInformationA"
  c_SetupQueryInfVersionInformationA :: Ptr () -> Word32 -> CString -> CString -> Word32 -> Ptr Word32 -> IO CInt
-- InfInformation : SP_INF_INFORMATION* -> Ptr ()
-- InfIndex : DWORD -> Word32
-- Key : LPCSTR optional -> CString
-- ReturnBuffer : LPSTR optional, out -> CString
-- ReturnBufferSize : DWORD -> Word32
-- RequiredSize : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupqueryinfversioninformationa =
  foreign "SetupQueryInfVersionInformationA"
    ((ptr void) @-> uint32_t @-> string @-> string @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* InfInformation : SP_INF_INFORMATION* -> (ptr void) *)
(* InfIndex : DWORD -> uint32_t *)
(* Key : LPCSTR optional -> string *)
(* ReturnBuffer : LPSTR optional, out -> string *)
(* 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 ("SetupQueryInfVersionInformationA" setup-query-inf-version-information-a :convention :stdcall) :int32
  (inf-information :pointer)   ; SP_INF_INFORMATION*
  (inf-index :uint32)   ; DWORD
  (key :string)   ; LPCSTR optional
  (return-buffer :pointer)   ; LPSTR 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 $SetupQueryInfVersionInformationA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupQueryInfVersionInformationA(LPVOID InfInformation, DWORD InfIndex, LPCSTR Key, LPSTR ReturnBuffer, DWORD ReturnBufferSize, LPVOID RequiredSize)');
# my $ret = $SetupQueryInfVersionInformationA->Call($InfInformation, $InfIndex, $Key, $ReturnBuffer, $ReturnBufferSize, $RequiredSize);
# InfInformation : SP_INF_INFORMATION* -> LPVOID
# InfIndex : DWORD -> DWORD
# Key : LPCSTR optional -> LPCSTR
# ReturnBuffer : LPSTR optional, out -> LPSTR
# ReturnBufferSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目
使用する型