ホーム › Devices.DeviceAndDriverInstallation › SetupGetSourceFileLocationW
SetupGetSourceFileLocationW
関数INFに記載されたソースファイルの場所を取得する(Unicode)。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupGetSourceFileLocationW(
void* InfHandle,
INFCONTEXT* InfContext, // optional
LPCWSTR FileName, // optional
DWORD* SourceId,
LPWSTR ReturnBuffer, // optional
DWORD ReturnBufferSize,
DWORD* RequiredSize // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| InfHandle | void* | in |
| InfContext | INFCONTEXT* | inoptional |
| FileName | LPCWSTR | inoptional |
| SourceId | DWORD* | out |
| ReturnBuffer | LPWSTR | outoptional |
| ReturnBufferSize | DWORD | in |
| RequiredSize | DWORD* | outoptional |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupGetSourceFileLocationW(
void* InfHandle,
INFCONTEXT* InfContext, // optional
LPCWSTR FileName, // optional
DWORD* SourceId,
LPWSTR ReturnBuffer, // optional
DWORD ReturnBufferSize,
DWORD* RequiredSize // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupGetSourceFileLocationW(
IntPtr InfHandle, // void*
IntPtr InfContext, // INFCONTEXT* optional
[MarshalAs(UnmanagedType.LPWStr)] string FileName, // LPCWSTR optional
out uint SourceId, // DWORD* out
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ReturnBuffer, // LPWSTR optional, out
uint ReturnBufferSize, // DWORD
IntPtr RequiredSize // DWORD* optional, out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupGetSourceFileLocationW(
InfHandle As IntPtr, ' void*
InfContext As IntPtr, ' INFCONTEXT* optional
<MarshalAs(UnmanagedType.LPWStr)> FileName As String, ' LPCWSTR optional
<Out> ByRef SourceId As UInteger, ' DWORD* out
<MarshalAs(UnmanagedType.LPWStr)> ReturnBuffer As System.Text.StringBuilder, ' LPWSTR optional, out
ReturnBufferSize As UInteger, ' DWORD
RequiredSize As IntPtr ' DWORD* optional, out
) As Boolean
End Function' InfHandle : void*
' InfContext : INFCONTEXT* optional
' FileName : LPCWSTR optional
' SourceId : DWORD* out
' ReturnBuffer : LPWSTR optional, out
' ReturnBufferSize : DWORD
' RequiredSize : DWORD* optional, out
Declare PtrSafe Function SetupGetSourceFileLocationW Lib "setupapi" ( _
ByVal InfHandle As LongPtr, _
ByVal InfContext As LongPtr, _
ByVal FileName As LongPtr, _
ByRef SourceId 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
SetupGetSourceFileLocationW = ctypes.windll.setupapi.SetupGetSourceFileLocationW
SetupGetSourceFileLocationW.restype = wintypes.BOOL
SetupGetSourceFileLocationW.argtypes = [
ctypes.POINTER(None), # InfHandle : void*
ctypes.c_void_p, # InfContext : INFCONTEXT* optional
wintypes.LPCWSTR, # FileName : LPCWSTR optional
ctypes.POINTER(wintypes.DWORD), # SourceId : DWORD* out
wintypes.LPWSTR, # ReturnBuffer : LPWSTR 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')
SetupGetSourceFileLocationW = Fiddle::Function.new(
lib['SetupGetSourceFileLocationW'],
[
Fiddle::TYPE_VOIDP, # InfHandle : void*
Fiddle::TYPE_VOIDP, # InfContext : INFCONTEXT* optional
Fiddle::TYPE_VOIDP, # FileName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # SourceId : DWORD* out
Fiddle::TYPE_VOIDP, # ReturnBuffer : LPWSTR 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 SetupGetSourceFileLocationW(
InfHandle: *mut (), // void*
InfContext: *mut INFCONTEXT, // INFCONTEXT* optional
FileName: *const u16, // LPCWSTR optional
SourceId: *mut u32, // DWORD* out
ReturnBuffer: *mut u16, // LPWSTR 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 SetupGetSourceFileLocationW(IntPtr InfHandle, IntPtr InfContext, [MarshalAs(UnmanagedType.LPWStr)] string FileName, out uint SourceId, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetSourceFileLocationW' -Namespace Win32 -PassThru
# $api::SetupGetSourceFileLocationW(InfHandle, InfContext, FileName, SourceId, ReturnBuffer, ReturnBufferSize, RequiredSize)#uselib "SETUPAPI.dll"
#func global SetupGetSourceFileLocationW "SetupGetSourceFileLocationW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupGetSourceFileLocationW InfHandle, varptr(InfContext), FileName, varptr(SourceId), varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize) ; 戻り値は stat
; InfHandle : void* -> "wptr"
; InfContext : INFCONTEXT* optional -> "wptr"
; FileName : LPCWSTR optional -> "wptr"
; SourceId : DWORD* out -> "wptr"
; ReturnBuffer : LPWSTR optional, out -> "wptr"
; ReturnBufferSize : DWORD -> "wptr"
; RequiredSize : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupGetSourceFileLocationW "SetupGetSourceFileLocationW" sptr, var, wstr, var, var, int, var ; res = SetupGetSourceFileLocationW(InfHandle, InfContext, FileName, SourceId, ReturnBuffer, ReturnBufferSize, RequiredSize) ; InfHandle : void* -> "sptr" ; InfContext : INFCONTEXT* optional -> "var" ; FileName : LPCWSTR optional -> "wstr" ; SourceId : DWORD* out -> "var" ; ReturnBuffer : LPWSTR optional, out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupGetSourceFileLocationW "SetupGetSourceFileLocationW" sptr, sptr, wstr, sptr, sptr, int, sptr ; res = SetupGetSourceFileLocationW(InfHandle, varptr(InfContext), FileName, varptr(SourceId), varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; InfHandle : void* -> "sptr" ; InfContext : INFCONTEXT* optional -> "sptr" ; FileName : LPCWSTR optional -> "wstr" ; SourceId : DWORD* out -> "sptr" ; ReturnBuffer : LPWSTR optional, out -> "sptr" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupGetSourceFileLocationW(void* InfHandle, INFCONTEXT* InfContext, LPCWSTR FileName, DWORD* SourceId, LPWSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetSourceFileLocationW "SetupGetSourceFileLocationW" intptr, var, wstr, var, var, int, var ; res = SetupGetSourceFileLocationW(InfHandle, InfContext, FileName, SourceId, ReturnBuffer, ReturnBufferSize, RequiredSize) ; InfHandle : void* -> "intptr" ; InfContext : INFCONTEXT* optional -> "var" ; FileName : LPCWSTR optional -> "wstr" ; SourceId : DWORD* out -> "var" ; ReturnBuffer : LPWSTR optional, out -> "var" ; ReturnBufferSize : DWORD -> "int" ; RequiredSize : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupGetSourceFileLocationW(void* InfHandle, INFCONTEXT* InfContext, LPCWSTR FileName, DWORD* SourceId, LPWSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize) #uselib "SETUPAPI.dll" #cfunc global SetupGetSourceFileLocationW "SetupGetSourceFileLocationW" intptr, intptr, wstr, intptr, intptr, int, intptr ; res = SetupGetSourceFileLocationW(InfHandle, varptr(InfContext), FileName, varptr(SourceId), varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)) ; InfHandle : void* -> "intptr" ; InfContext : INFCONTEXT* optional -> "intptr" ; FileName : LPCWSTR optional -> "wstr" ; SourceId : DWORD* out -> "intptr" ; ReturnBuffer : LPWSTR 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")
procSetupGetSourceFileLocationW = setupapi.NewProc("SetupGetSourceFileLocationW")
)
// InfHandle (void*), InfContext (INFCONTEXT* optional), FileName (LPCWSTR optional), SourceId (DWORD* out), ReturnBuffer (LPWSTR optional, out), ReturnBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupGetSourceFileLocationW.Call(
uintptr(InfHandle),
uintptr(InfContext),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileName))),
uintptr(SourceId),
uintptr(ReturnBuffer),
uintptr(ReturnBufferSize),
uintptr(RequiredSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupGetSourceFileLocationW(
InfHandle: Pointer; // void*
InfContext: Pointer; // INFCONTEXT* optional
FileName: PWideChar; // LPCWSTR optional
SourceId: Pointer; // DWORD* out
ReturnBuffer: PWideChar; // LPWSTR optional, out
ReturnBufferSize: DWORD; // DWORD
RequiredSize: Pointer // DWORD* optional, out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetSourceFileLocationW';result := DllCall("SETUPAPI\SetupGetSourceFileLocationW"
, "Ptr", InfHandle ; void*
, "Ptr", InfContext ; INFCONTEXT* optional
, "WStr", FileName ; LPCWSTR optional
, "Ptr", SourceId ; DWORD* out
, "Ptr", ReturnBuffer ; LPWSTR optional, out
, "UInt", ReturnBufferSize ; DWORD
, "Ptr", RequiredSize ; DWORD* optional, out
, "Int") ; return: BOOL●SetupGetSourceFileLocationW(InfHandle, InfContext, FileName, SourceId, ReturnBuffer, ReturnBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupGetSourceFileLocationW(void*, void*, char*, void*, char*, dword, void*)")
# 呼び出し: SetupGetSourceFileLocationW(InfHandle, InfContext, FileName, SourceId, ReturnBuffer, ReturnBufferSize, RequiredSize)
# InfHandle : void* -> "void*"
# InfContext : INFCONTEXT* optional -> "void*"
# FileName : LPCWSTR optional -> "char*"
# SourceId : DWORD* out -> "void*"
# ReturnBuffer : LPWSTR optional, out -> "char*"
# ReturnBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。