ホーム › Devices.DeviceAndDriverInstallation › SetupGetSourceInfoA
SetupGetSourceInfoA
関数INFの指定ソースの情報(パスやタグ等)を取得する(ANSI)。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupGetSourceInfoA(
void* InfHandle,
DWORD SourceId,
DWORD InfoDesired,
LPSTR ReturnBuffer, // optional
DWORD ReturnBufferSize,
DWORD* RequiredSize // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InfHandle | void* | in | 対象の開いているINFハンドル。 |
| SourceId | DWORD | in | 情報を取得するソースメディアのID。 |
| InfoDesired | DWORD | in | 取得したい情報の種別(パス/タグファイル/説明)を示す値。 |
| ReturnBuffer | LPSTR | outoptional | 要求した情報文字列を受け取るバッファ(ANSI)。NULLでサイズ取得のみ可。 |
| ReturnBufferSize | DWORD | in | ReturnBufferのサイズ(文字数)。 |
| RequiredSize | DWORD* | outoptional | 必要なバッファサイズを受け取る出力ポインタ。NULL可。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupGetSourceInfoA(
void* InfHandle,
DWORD SourceId,
DWORD InfoDesired,
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 SetupGetSourceInfoA(
IntPtr InfHandle, // void*
uint SourceId, // DWORD
uint InfoDesired, // DWORD
[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 SetupGetSourceInfoA(
InfHandle As IntPtr, ' void*
SourceId As UInteger, ' DWORD
InfoDesired As UInteger, ' DWORD
<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' InfHandle : void*
' SourceId : DWORD
' InfoDesired : DWORD
' ReturnBuffer : LPSTR optional, out
' ReturnBufferSize : DWORD
' RequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupGetSourceInfoA Lib "setupapi" ( _
ByVal InfHandle As LongPtr, _
ByVal SourceId As Long, _
ByVal InfoDesired As Long, _
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
SetupGetSourceInfoA = ctypes.windll.setupapi.SetupGetSourceInfoA
SetupGetSourceInfoA.restype = wintypes.BOOL
SetupGetSourceInfoA.argtypes = [
ctypes.POINTER(None), # InfHandle : void*
wintypes.DWORD, # SourceId : DWORD
wintypes.DWORD, # InfoDesired : DWORD
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')
SetupGetSourceInfoA = Fiddle::Function.new(
lib['SetupGetSourceInfoA'],
[
Fiddle::TYPE_VOIDP, # InfHandle : void*
-Fiddle::TYPE_INT, # SourceId : DWORD
-Fiddle::TYPE_INT, # InfoDesired : DWORD
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 SetupGetSourceInfoA(
InfHandle: *mut (), // void*
SourceId: u32, // DWORD
InfoDesired: u32, // DWORD
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 SetupGetSourceInfoA(IntPtr InfHandle, uint SourceId, uint InfoDesired, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetSourceInfoA' -Namespace Win32 -PassThru
# $api::SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize)#uselib "SETUPAPI.dll"
#func global SetupGetSourceInfoA "SetupGetSourceInfoA" sptr, sptr, sptr, sptr, sptr, sptr
; SetupGetSourceInfoA InfHandle, SourceId, InfoDesired, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize) ; 戻り値は stat
; InfHandle : void* -> "sptr"
; SourceId : DWORD -> "sptr"
; InfoDesired : DWORD -> "sptr"
; ReturnBuffer : LPSTR optional, out -> "sptr"
; ReturnBufferSize : DWORD -> "sptr"
; RequiredSize : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupGetSourceInfoA "SetupGetSourceInfoA" sptr, int, int, var, int, var ; res = SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize) ; InfHandle : void* -> "sptr" ; SourceId : DWORD -> "int" ; InfoDesired : DWORD -> "int" ; ReturnBuffer : LPSTR optional, out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupGetSourceInfoA "SetupGetSourceInfoA" sptr, int, int, sptr, int, sptr ; res = SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; InfHandle : void* -> "sptr" ; SourceId : DWORD -> "int" ; InfoDesired : DWORD -> "int" ; ReturnBuffer : LPSTR optional, out -> "sptr" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupGetSourceInfoA(void* InfHandle, DWORD SourceId, DWORD InfoDesired, LPSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetSourceInfoA "SetupGetSourceInfoA" intptr, int, int, var, int, var ; res = SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize) ; InfHandle : void* -> "intptr" ; SourceId : DWORD -> "int" ; InfoDesired : DWORD -> "int" ; ReturnBuffer : LPSTR optional, out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupGetSourceInfoA(void* InfHandle, DWORD SourceId, DWORD InfoDesired, LPSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetSourceInfoA "SetupGetSourceInfoA" intptr, int, int, intptr, int, intptr ; res = SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; InfHandle : void* -> "intptr" ; SourceId : DWORD -> "int" ; InfoDesired : DWORD -> "int" ; ReturnBuffer : LPSTR 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")
procSetupGetSourceInfoA = setupapi.NewProc("SetupGetSourceInfoA")
)
// InfHandle (void*), SourceId (DWORD), InfoDesired (DWORD), ReturnBuffer (LPSTR optional, out), ReturnBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupGetSourceInfoA.Call(
uintptr(InfHandle),
uintptr(SourceId),
uintptr(InfoDesired),
uintptr(ReturnBuffer),
uintptr(ReturnBufferSize),
uintptr(RequiredSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupGetSourceInfoA(
InfHandle: Pointer; // void*
SourceId: DWORD; // DWORD
InfoDesired: DWORD; // DWORD
ReturnBuffer: PAnsiChar; // LPSTR optional, out
ReturnBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetSourceInfoA';result := DllCall("SETUPAPI\SetupGetSourceInfoA"
, "Ptr", InfHandle ; void*
, "UInt", SourceId ; DWORD
, "UInt", InfoDesired ; DWORD
, "Ptr", ReturnBuffer ; LPSTR optional, out
, "UInt", ReturnBufferSize ; DWORD
, "Ptr", RequiredSize ; DWORD* optional, out
, "Int") ; return: BOOL●SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupGetSourceInfoA(void*, dword, dword, char*, dword, void*)")
# 呼び出し: SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize)
# InfHandle : void* -> "void*"
# SourceId : DWORD -> "dword"
# InfoDesired : DWORD -> "dword"
# 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 SetupGetSourceInfoA(
InfHandle: ?*anyopaque, // void*
SourceId: u32, // DWORD
InfoDesired: u32, // DWORD
ReturnBuffer: [*c]u8, // LPSTR optional, out
ReturnBufferSize: u32, // DWORD
RequiredSize: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;proc SetupGetSourceInfoA(
InfHandle: pointer, # void*
SourceId: uint32, # DWORD
InfoDesired: uint32, # DWORD
ReturnBuffer: ptr char, # LPSTR optional, out
ReturnBufferSize: uint32, # DWORD
RequiredSize: ptr uint32 # DWORD* optional, out
): int32 {.importc: "SetupGetSourceInfoA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupGetSourceInfoA(
void* InfHandle, // void*
uint SourceId, // DWORD
uint InfoDesired, // DWORD
char* ReturnBuffer, // LPSTR optional, out
uint ReturnBufferSize, // DWORD
uint* RequiredSize // DWORD* optional, out
);ccall((:SetupGetSourceInfoA, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}),
InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize)
# InfHandle : void* -> Ptr{Cvoid}
# SourceId : DWORD -> UInt32
# InfoDesired : DWORD -> UInt32
# 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 SetupGetSourceInfoA(
void* InfHandle,
uint32_t SourceId,
uint32_t InfoDesired,
char* ReturnBuffer,
uint32_t ReturnBufferSize,
uint32_t* RequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize)
-- InfHandle : void*
-- SourceId : DWORD
-- InfoDesired : DWORD
-- 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 SetupGetSourceInfoA = lib.func('__stdcall', 'SetupGetSourceInfoA', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'char *', 'uint32_t', 'uint32_t *']);
// SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize)
// InfHandle : void* -> 'void *'
// SourceId : DWORD -> 'uint32_t'
// InfoDesired : DWORD -> 'uint32_t'
// 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", {
SetupGetSourceInfoA: { parameters: ["pointer", "u32", "u32", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize)
// InfHandle : void* -> "pointer"
// SourceId : DWORD -> "u32"
// InfoDesired : DWORD -> "u32"
// 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 SetupGetSourceInfoA(
void* InfHandle,
uint32_t SourceId,
uint32_t InfoDesired,
char* ReturnBuffer,
uint32_t ReturnBufferSize,
uint32_t* RequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupGetSourceInfoA(InfHandle, SourceId, InfoDesired, ReturnBuffer, ReturnBufferSize, RequiredSize);
// InfHandle : void*
// SourceId : DWORD
// InfoDesired : DWORD
// 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 SetupGetSourceInfoA(
Pointer InfHandle, // void*
int SourceId, // DWORD
int InfoDesired, // DWORD
byte[] ReturnBuffer, // LPSTR optional, out
int ReturnBufferSize, // DWORD
IntByReference RequiredSize // DWORD* optional, out
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupGetSourceInfoA = SetupGetSourceInfoA(
InfHandle : Void*, # void*
SourceId : UInt32, # DWORD
InfoDesired : UInt32, # DWORD
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 SetupGetSourceInfoANative = Int32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Utf8>, Uint32, Pointer<Uint32>);
typedef SetupGetSourceInfoADart = int Function(Pointer<Void>, int, int, Pointer<Utf8>, int, Pointer<Uint32>);
final SetupGetSourceInfoA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupGetSourceInfoANative, SetupGetSourceInfoADart>('SetupGetSourceInfoA');
// InfHandle : void* -> Pointer<Void>
// SourceId : DWORD -> Uint32
// InfoDesired : DWORD -> Uint32
// ReturnBuffer : LPSTR optional, out -> Pointer<Utf8>
// ReturnBufferSize : DWORD -> Uint32
// RequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupGetSourceInfoA(
InfHandle: Pointer; // void*
SourceId: DWORD; // DWORD
InfoDesired: DWORD; // DWORD
ReturnBuffer: PAnsiChar; // LPSTR optional, out
ReturnBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetSourceInfoA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupGetSourceInfoA"
c_SetupGetSourceInfoA :: Ptr () -> Word32 -> Word32 -> CString -> Word32 -> Ptr Word32 -> IO CInt
-- InfHandle : void* -> Ptr ()
-- SourceId : DWORD -> Word32
-- InfoDesired : DWORD -> Word32
-- 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 setupgetsourceinfoa =
foreign "SetupGetSourceInfoA"
((ptr void) @-> uint32_t @-> uint32_t @-> string @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* SourceId : DWORD -> uint32_t *)
(* InfoDesired : DWORD -> uint32_t *)
(* 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 ("SetupGetSourceInfoA" setup-get-source-info-a :convention :stdcall) :int32
(inf-handle :pointer) ; void*
(source-id :uint32) ; DWORD
(info-desired :uint32) ; DWORD
(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 $SetupGetSourceInfoA = Win32::API::More->new('SETUPAPI',
'BOOL SetupGetSourceInfoA(LPVOID InfHandle, DWORD SourceId, DWORD InfoDesired, LPSTR ReturnBuffer, DWORD ReturnBufferSize, LPVOID RequiredSize)');
# my $ret = $SetupGetSourceInfoA->Call($InfHandle, $SourceId, $InfoDesired, $ReturnBuffer, $ReturnBufferSize, $RequiredSize);
# InfHandle : void* -> LPVOID
# SourceId : DWORD -> DWORD
# InfoDesired : DWORD -> DWORD
# ReturnBuffer : LPSTR optional, out -> LPSTR
# ReturnBufferSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupGetSourceInfoW (Unicode版) — INFの指定ソースの情報(パスやタグ等)を取得する(Unicode)。