SetupGetInfDriverStoreLocationW
関数シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupGetInfDriverStoreLocationW(
LPCWSTR FileName,
SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo, // optional
LPCWSTR LocaleName, // optional
LPWSTR ReturnBuffer,
DWORD ReturnBufferSize,
DWORD* RequiredSize // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileName | LPCWSTR | in | システムの INF ファイルディレクトリ内にある INF ファイルの名前 (省略可能で完全なディレクトリパスを含む) を格納した、NULL で終わる文字列へのポインター。あるいは、ドライバーストア内の INF ファイルの完全修飾ファイル名 (ディレクトリパスとファイル名) を格納した、NULL で終わる文字列へのポインターを指定します。 INF ファイルの指定方法の詳細については、後述の 解説 セクションを参照してください。 |
| AlternatePlatformInfo | SP_ALTPLATFORM_INFO_V2* | inoptional | システムによる使用のために予約されています。 |
| LocaleName | LPCWSTR | inoptional | システムによる使用のために予約されています。 |
| ReturnBuffer | LPWSTR | out | 指定した INF ファイルの完全修飾ファイル名を格納する、NULL で終わる文字列を関数が返すバッファーへのポインター。このパラメーターには NULL を設定できます。サポートされる最大のパスサイズは MAX_PATH です。バッファーに必要なサイズを判断する方法については、後述の 解説 セクションを参照してください。 |
| ReturnBufferSize | DWORD | in | ReturnBuffer で指定されたバッファーのサイズ (文字数)。 |
| RequiredSize | DWORD* | outoptional | ReturnBuffer バッファーのサイズ (文字数) を受け取る DWORD 型の変数へのポインター。このパラメーターは省略可能であり、NULL を設定できます。 |
戻り値の型: BOOL
公式ドキュメント
SetupGetInfDriverStoreLocation 関数は、システムの INF ファイルディレクトリ内の指定された INF ファイル、またはドライバーストア内の指定された INF ファイルに対応する、ドライバーストア内の INF ファイルの完全修飾ファイル名 (ディレクトリパスとファイル名) を取得します。(Unicode)
戻り値
SetupGetInfDriverStoreLocation が成功した場合、この関数は TRUE を返します。それ以外の場合は FALSE を返します。拡張エラー情報を取得するには、GetLastError を呼び出します。
要求された INF ファイルの完全修飾ファイル名のサイズ (null 終端文字を含む文字数) が ReturnBufferSize より大きい場合、この関数は失敗し、GetLastError の呼び出しは ERROR_INSUFFICIENT_BUFFER を返します。
解説(Remarks)
ドライバーストア内の指定された INF ファイルの完全修飾ファイル名を格納するために必要な戻りバッファーのサイズを判断するには、ReturnBuffer に NULL、ReturnBufferSize に 0 を設定し、RequiredSize を指定して SetupGetInfDriverStoreLocation を呼び出します。SetupGetInfDriverStoreLocation は、必要なバッファーサイズを RequiredSize で返します。
デバイスのインストールでドライバーパッケージをドライバーストアにプレインストールすると、ドライバーパッケージの INF ファイルのコピーが 2 つ作成されます。デバイスのインストールでは、一方のコピーがシステムの INF ディレクトリにインストールされ、その INF ファイルのコピーには OEMnnn.inf 形式の一意の公開ファイル名が割り当てられます。もう一方の INF ファイルのコピーはドライバーストアにインストールされ、そのコピーには元の INF ファイル名が割り当てられます。
SetupGetInfDriverStoreLocation は、FileName で指定された INF ファイルに一致する INF ファイルがドライバーストア内に存在する場合、その完全修飾ファイル名を返します。Filename には、システムの INF ディレクトリ内にある INF ファイルのファイル名 (省略可能でディレクトリパスも) を指定する必要があります。あるいは、Filename にはドライバーストア内の INF ファイルの完全修飾ファイル名を指定する必要があります。
たとえば、あるドライバーパッケージの INF ファイルが Myinf.inf であり、このドライバーパッケージについて、デバイスのインストールがシステムの INF ディレクトリ C:\Windows\inf に INF ファイル OEM1.inf をインストールしたとします。さらに、デバイスのインストールが対応する INF ファイルのコピー C:\windows\system32\driverstore\filerepository\myinf_12345678\myinf.inf をドライバーストアにインストールしたとします。この場合、FileName に OEM1.inf、C:\Windows\inf\OEM1.inf、C:\windows\system32\driverstore\filerepository\myinf_12345678\myinf.inf のいずれかの文字列が指定されると、関数は C:\windows\system32\driverstore\filerepository\myinf_12345678\myinf.inf を返します。
クラスインストーラーおよびコインストーラーは、SetupGetInfDriverStoreLocation を使用して、ドライバーストアにプレインストールされているドライバーパッケージ内のファイルにアクセスできます。ドライバーストア内のドライバーパッケージのパスを判断するには、インストーラーは次の処理を行います。
- SetupDiGetDriverInfoDetail を呼び出して、ドライバーの SP_DRVINFO_DETAIL_DATA 構造体を取得します。この構造体の InfFileName メンバーには、システムの INF ディレクトリ内にあるドライバー INF ファイルの完全修飾ファイル名が格納されます。
- SetupGetInfDriverStoreLocation を呼び出し、SetupDiGetDriverInfoDetail の呼び出しによって取得したドライバー INF ファイルの完全修飾ファイル名を指定します。SetupGetInfDriverStoreLocation は、ドライバーストア内のドライバー INF ファイルの完全修飾ファイル名を返します。この INF ファイルの完全修飾ファイル名のディレクトリパス部分が、ドライバーパッケージのファイルのパスです。
setupapi.h ヘッダーは、SetupGetInfDriverStoreLocation を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、不整合が生じ、コンパイルエラーまたは実行時エラーの原因となる可能性があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupGetInfDriverStoreLocationW(
LPCWSTR FileName,
SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo, // optional
LPCWSTR LocaleName, // optional
LPWSTR ReturnBuffer,
DWORD ReturnBufferSize,
DWORD* RequiredSize // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupGetInfDriverStoreLocationW(
[MarshalAs(UnmanagedType.LPWStr)] string FileName, // LPCWSTR
IntPtr AlternatePlatformInfo, // SP_ALTPLATFORM_INFO_V2* optional
[MarshalAs(UnmanagedType.LPWStr)] string LocaleName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ReturnBuffer, // LPWSTR out
uint ReturnBufferSize, // DWORD
IntPtr RequiredSize // DWORD* optional, out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupGetInfDriverStoreLocationW(
<MarshalAs(UnmanagedType.LPWStr)> FileName As String, ' LPCWSTR
AlternatePlatformInfo As IntPtr, ' SP_ALTPLATFORM_INFO_V2* optional
<MarshalAs(UnmanagedType.LPWStr)> LocaleName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> ReturnBuffer As System.Text.StringBuilder, ' LPWSTR out
ReturnBufferSize As UInteger, ' DWORD
RequiredSize As IntPtr ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' FileName : LPCWSTR
' AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
' LocaleName : LPCWSTR optional
' ReturnBuffer : LPWSTR out
' ReturnBufferSize : DWORD
' RequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupGetInfDriverStoreLocationW Lib "setupapi" ( _
ByVal FileName As LongPtr, _
ByVal AlternatePlatformInfo As LongPtr, _
ByVal LocaleName As LongPtr, _
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
SetupGetInfDriverStoreLocationW = ctypes.windll.setupapi.SetupGetInfDriverStoreLocationW
SetupGetInfDriverStoreLocationW.restype = wintypes.BOOL
SetupGetInfDriverStoreLocationW.argtypes = [
wintypes.LPCWSTR, # FileName : LPCWSTR
ctypes.c_void_p, # AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
wintypes.LPCWSTR, # LocaleName : LPCWSTR optional
wintypes.LPWSTR, # ReturnBuffer : LPWSTR 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')
SetupGetInfDriverStoreLocationW = Fiddle::Function.new(
lib['SetupGetInfDriverStoreLocationW'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCWSTR
Fiddle::TYPE_VOIDP, # AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
Fiddle::TYPE_VOIDP, # LocaleName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # ReturnBuffer : LPWSTR 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 SetupGetInfDriverStoreLocationW(
FileName: *const u16, // LPCWSTR
AlternatePlatformInfo: *mut SP_ALTPLATFORM_INFO_V2, // SP_ALTPLATFORM_INFO_V2* optional
LocaleName: *const u16, // LPCWSTR optional
ReturnBuffer: *mut u16, // LPWSTR 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 SetupGetInfDriverStoreLocationW([MarshalAs(UnmanagedType.LPWStr)] string FileName, IntPtr AlternatePlatformInfo, [MarshalAs(UnmanagedType.LPWStr)] string LocaleName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetInfDriverStoreLocationW' -Namespace Win32 -PassThru
# $api::SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize)#uselib "SETUPAPI.dll"
#func global SetupGetInfDriverStoreLocationW "SetupGetInfDriverStoreLocationW" wptr, wptr, wptr, wptr, wptr, wptr
; SetupGetInfDriverStoreLocationW FileName, varptr(AlternatePlatformInfo), LocaleName, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize) ; 戻り値は stat
; FileName : LPCWSTR -> "wptr"
; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "wptr"
; LocaleName : LPCWSTR optional -> "wptr"
; ReturnBuffer : LPWSTR out -> "wptr"
; ReturnBufferSize : DWORD -> "wptr"
; RequiredSize : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll" #cfunc global SetupGetInfDriverStoreLocationW "SetupGetInfDriverStoreLocationW" wstr, var, wstr, var, int, var ; res = SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize) ; FileName : LPCWSTR -> "wstr" ; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "var" ; LocaleName : LPCWSTR optional -> "wstr" ; ReturnBuffer : LPWSTR out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupGetInfDriverStoreLocationW "SetupGetInfDriverStoreLocationW" wstr, sptr, wstr, sptr, int, sptr ; res = SetupGetInfDriverStoreLocationW(FileName, varptr(AlternatePlatformInfo), LocaleName, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; FileName : LPCWSTR -> "wstr" ; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "sptr" ; LocaleName : LPCWSTR optional -> "wstr" ; ReturnBuffer : LPWSTR out -> "sptr" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL SetupGetInfDriverStoreLocationW(LPCWSTR FileName, SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo, LPCWSTR LocaleName, LPWSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetInfDriverStoreLocationW "SetupGetInfDriverStoreLocationW" wstr, var, wstr, var, int, var ; res = SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize) ; FileName : LPCWSTR -> "wstr" ; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "var" ; LocaleName : LPCWSTR optional -> "wstr" ; ReturnBuffer : LPWSTR out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupGetInfDriverStoreLocationW(LPCWSTR FileName, SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo, LPCWSTR LocaleName, LPWSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetInfDriverStoreLocationW "SetupGetInfDriverStoreLocationW" wstr, intptr, wstr, intptr, int, intptr ; res = SetupGetInfDriverStoreLocationW(FileName, varptr(AlternatePlatformInfo), LocaleName, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; FileName : LPCWSTR -> "wstr" ; AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "intptr" ; LocaleName : LPCWSTR optional -> "wstr" ; ReturnBuffer : LPWSTR 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")
procSetupGetInfDriverStoreLocationW = setupapi.NewProc("SetupGetInfDriverStoreLocationW")
)
// FileName (LPCWSTR), AlternatePlatformInfo (SP_ALTPLATFORM_INFO_V2* optional), LocaleName (LPCWSTR optional), ReturnBuffer (LPWSTR out), ReturnBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupGetInfDriverStoreLocationW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileName))),
uintptr(AlternatePlatformInfo),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(LocaleName))),
uintptr(ReturnBuffer),
uintptr(ReturnBufferSize),
uintptr(RequiredSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupGetInfDriverStoreLocationW(
FileName: PWideChar; // LPCWSTR
AlternatePlatformInfo: Pointer; // SP_ALTPLATFORM_INFO_V2* optional
LocaleName: PWideChar; // LPCWSTR optional
ReturnBuffer: PWideChar; // LPWSTR out
ReturnBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetInfDriverStoreLocationW';result := DllCall("SETUPAPI\SetupGetInfDriverStoreLocationW"
, "WStr", FileName ; LPCWSTR
, "Ptr", AlternatePlatformInfo ; SP_ALTPLATFORM_INFO_V2* optional
, "WStr", LocaleName ; LPCWSTR optional
, "Ptr", ReturnBuffer ; LPWSTR out
, "UInt", ReturnBufferSize ; DWORD
, "Ptr", RequiredSize ; DWORD* optional, out
, "Int") ; return: BOOL●SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupGetInfDriverStoreLocationW(char*, void*, char*, char*, dword, void*)")
# 呼び出し: SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize)
# FileName : LPCWSTR -> "char*"
# AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "void*"
# LocaleName : LPCWSTR optional -> "char*"
# ReturnBuffer : LPWSTR out -> "char*"
# 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 SetupGetInfDriverStoreLocationW(
FileName: [*c]const u16, // LPCWSTR
AlternatePlatformInfo: [*c]SP_ALTPLATFORM_INFO_V2, // SP_ALTPLATFORM_INFO_V2* optional
LocaleName: [*c]const u16, // LPCWSTR optional
ReturnBuffer: [*c]u16, // LPWSTR out
ReturnBufferSize: u32, // DWORD
RequiredSize: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupGetInfDriverStoreLocationW(
FileName: WideCString, # LPCWSTR
AlternatePlatformInfo: ptr SP_ALTPLATFORM_INFO_V2, # SP_ALTPLATFORM_INFO_V2* optional
LocaleName: WideCString, # LPCWSTR optional
ReturnBuffer: ptr uint16, # LPWSTR out
ReturnBufferSize: uint32, # DWORD
RequiredSize: ptr uint32 # DWORD* optional, out
): int32 {.importc: "SetupGetInfDriverStoreLocationW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
int SetupGetInfDriverStoreLocationW(
const(wchar)* FileName, // LPCWSTR
SP_ALTPLATFORM_INFO_V2* AlternatePlatformInfo, // SP_ALTPLATFORM_INFO_V2* optional
const(wchar)* LocaleName, // LPCWSTR optional
wchar* ReturnBuffer, // LPWSTR out
uint ReturnBufferSize, // DWORD
uint* RequiredSize // DWORD* optional, out
);ccall((:SetupGetInfDriverStoreLocationW, "SETUPAPI.dll"), stdcall, Int32,
(Cwstring, Ptr{SP_ALTPLATFORM_INFO_V2}, Cwstring, Ptr{UInt16}, UInt32, Ptr{UInt32}),
FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize)
# FileName : LPCWSTR -> Cwstring
# AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> Ptr{SP_ALTPLATFORM_INFO_V2}
# LocaleName : LPCWSTR optional -> Cwstring
# ReturnBuffer : LPWSTR out -> Ptr{UInt16}
# 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 SetupGetInfDriverStoreLocationW(
const uint16_t* FileName,
void* AlternatePlatformInfo,
const uint16_t* LocaleName,
uint16_t* ReturnBuffer,
uint32_t ReturnBufferSize,
uint32_t* RequiredSize);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize)
-- FileName : LPCWSTR
-- AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
-- LocaleName : LPCWSTR optional
-- ReturnBuffer : LPWSTR 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 SetupGetInfDriverStoreLocationW = lib.func('__stdcall', 'SetupGetInfDriverStoreLocationW', 'int32_t', ['str16', 'void *', 'str16', 'uint16_t *', 'uint32_t', 'uint32_t *']);
// SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize)
// FileName : LPCWSTR -> 'str16'
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> 'void *'
// LocaleName : LPCWSTR optional -> 'str16'
// ReturnBuffer : LPWSTR out -> 'uint16_t *'
// ReturnBufferSize : DWORD -> 'uint32_t'
// RequiredSize : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupGetInfDriverStoreLocationW: { parameters: ["buffer", "pointer", "buffer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize)
// FileName : LPCWSTR -> "buffer"
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> "pointer"
// LocaleName : LPCWSTR optional -> "buffer"
// ReturnBuffer : LPWSTR out -> "buffer"
// 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 SetupGetInfDriverStoreLocationW(
const uint16_t* FileName,
void* AlternatePlatformInfo,
const uint16_t* LocaleName,
uint16_t* ReturnBuffer,
uint32_t ReturnBufferSize,
uint32_t* RequiredSize);
C, "SETUPAPI.dll");
// $ffi->SetupGetInfDriverStoreLocationW(FileName, AlternatePlatformInfo, LocaleName, ReturnBuffer, ReturnBufferSize, RequiredSize);
// FileName : LPCWSTR
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional
// LocaleName : LPCWSTR optional
// ReturnBuffer : LPWSTR 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 SetupGetInfDriverStoreLocationW(
WString FileName, // LPCWSTR
Pointer AlternatePlatformInfo, // SP_ALTPLATFORM_INFO_V2* optional
WString LocaleName, // LPCWSTR optional
char[] ReturnBuffer, // LPWSTR out
int ReturnBufferSize, // DWORD
IntByReference RequiredSize // DWORD* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupGetInfDriverStoreLocationW = SetupGetInfDriverStoreLocationW(
FileName : UInt16*, # LPCWSTR
AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2*, # SP_ALTPLATFORM_INFO_V2* optional
LocaleName : UInt16*, # LPCWSTR optional
ReturnBuffer : UInt16*, # LPWSTR 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 SetupGetInfDriverStoreLocationWNative = Int32 Function(Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Uint32>);
typedef SetupGetInfDriverStoreLocationWDart = int Function(Pointer<Utf16>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Uint32>);
final SetupGetInfDriverStoreLocationW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupGetInfDriverStoreLocationWNative, SetupGetInfDriverStoreLocationWDart>('SetupGetInfDriverStoreLocationW');
// FileName : LPCWSTR -> Pointer<Utf16>
// AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> Pointer<Void>
// LocaleName : LPCWSTR optional -> Pointer<Utf16>
// ReturnBuffer : LPWSTR out -> Pointer<Utf16>
// ReturnBufferSize : DWORD -> Uint32
// RequiredSize : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupGetInfDriverStoreLocationW(
FileName: PWideChar; // LPCWSTR
AlternatePlatformInfo: Pointer; // SP_ALTPLATFORM_INFO_V2* optional
LocaleName: PWideChar; // LPCWSTR optional
ReturnBuffer: PWideChar; // LPWSTR out
ReturnBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetInfDriverStoreLocationW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupGetInfDriverStoreLocationW"
c_SetupGetInfDriverStoreLocationW :: CWString -> Ptr () -> CWString -> CWString -> Word32 -> Ptr Word32 -> IO CInt
-- FileName : LPCWSTR -> CWString
-- AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> Ptr ()
-- LocaleName : LPCWSTR optional -> CWString
-- ReturnBuffer : LPWSTR out -> CWString
-- ReturnBufferSize : DWORD -> Word32
-- RequiredSize : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupgetinfdriverstorelocationw =
foreign "SetupGetInfDriverStoreLocationW"
((ptr uint16_t) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* FileName : LPCWSTR -> (ptr uint16_t) *)
(* AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> (ptr void) *)
(* LocaleName : LPCWSTR optional -> (ptr uint16_t) *)
(* ReturnBuffer : LPWSTR out -> (ptr uint16_t) *)
(* 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 ("SetupGetInfDriverStoreLocationW" setup-get-inf-driver-store-location-w :convention :stdcall) :int32
(file-name (:string :encoding :utf-16le)) ; LPCWSTR
(alternate-platform-info :pointer) ; SP_ALTPLATFORM_INFO_V2* optional
(locale-name (:string :encoding :utf-16le)) ; LPCWSTR optional
(return-buffer :pointer) ; LPWSTR 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 $SetupGetInfDriverStoreLocationW = Win32::API::More->new('SETUPAPI',
'BOOL SetupGetInfDriverStoreLocationW(LPCWSTR FileName, LPVOID AlternatePlatformInfo, LPCWSTR LocaleName, LPWSTR ReturnBuffer, DWORD ReturnBufferSize, LPVOID RequiredSize)');
# my $ret = $SetupGetInfDriverStoreLocationW->Call($FileName, $AlternatePlatformInfo, $LocaleName, $ReturnBuffer, $ReturnBufferSize, $RequiredSize);
# FileName : LPCWSTR -> LPCWSTR
# AlternatePlatformInfo : SP_ALTPLATFORM_INFO_V2* optional -> LPVOID
# LocaleName : LPCWSTR optional -> LPCWSTR
# ReturnBuffer : LPWSTR out -> LPWSTR
# ReturnBufferSize : DWORD -> DWORD
# RequiredSize : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f SetupGetInfDriverStoreLocationA (ANSI版) — ドライバーストア内のINFファイルの場所を取得する(ANSI)。
- s SP_DRVINFO_DETAIL_DATA_W
- f SetupDiGetDriverInfoDetailW — 指定ドライバの詳細情報を取得する。
- f SetupGetInfPublishedNameW — ドライバーストア内のINFの公開名を取得する(Unicode)。