ホーム › System.ProcessStatus › GetDeviceDriverFileNameW
GetDeviceDriverFileNameW
関数デバイスドライバのファイルパスをUnicodeで取得する。
シグネチャ
// PSAPI.dll (Unicode / -W)
#include <windows.h>
DWORD GetDeviceDriverFileNameW(
void* ImageBase,
LPWSTR lpFilename,
DWORD nSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ImageBase | void* | in |
| lpFilename | LPWSTR | out |
| nSize | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// PSAPI.dll (Unicode / -W)
#include <windows.h>
DWORD GetDeviceDriverFileNameW(
void* ImageBase,
LPWSTR lpFilename,
DWORD nSize
);[DllImport("PSAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint GetDeviceDriverFileNameW(
IntPtr ImageBase, // void*
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpFilename, // LPWSTR out
uint nSize // DWORD
);<DllImport("PSAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetDeviceDriverFileNameW(
ImageBase As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> lpFilename As System.Text.StringBuilder, ' LPWSTR out
nSize As UInteger ' DWORD
) As UInteger
End Function' ImageBase : void*
' lpFilename : LPWSTR out
' nSize : DWORD
Declare PtrSafe Function GetDeviceDriverFileNameW Lib "psapi" ( _
ByVal ImageBase As LongPtr, _
ByVal lpFilename As LongPtr, _
ByVal nSize As Long) 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
GetDeviceDriverFileNameW = ctypes.windll.psapi.GetDeviceDriverFileNameW
GetDeviceDriverFileNameW.restype = wintypes.DWORD
GetDeviceDriverFileNameW.argtypes = [
ctypes.POINTER(None), # ImageBase : void*
wintypes.LPWSTR, # lpFilename : LPWSTR out
wintypes.DWORD, # nSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('PSAPI.dll')
GetDeviceDriverFileNameW = Fiddle::Function.new(
lib['GetDeviceDriverFileNameW'],
[
Fiddle::TYPE_VOIDP, # ImageBase : void*
Fiddle::TYPE_VOIDP, # lpFilename : LPWSTR out
-Fiddle::TYPE_INT, # nSize : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "psapi")]
extern "system" {
fn GetDeviceDriverFileNameW(
ImageBase: *mut (), // void*
lpFilename: *mut u16, // LPWSTR out
nSize: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("PSAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint GetDeviceDriverFileNameW(IntPtr ImageBase, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpFilename, uint nSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'PSAPI_GetDeviceDriverFileNameW' -Namespace Win32 -PassThru
# $api::GetDeviceDriverFileNameW(ImageBase, lpFilename, nSize)#uselib "PSAPI.dll"
#func global GetDeviceDriverFileNameW "GetDeviceDriverFileNameW" wptr, wptr, wptr
; GetDeviceDriverFileNameW ImageBase, varptr(lpFilename), nSize ; 戻り値は stat
; ImageBase : void* -> "wptr"
; lpFilename : LPWSTR out -> "wptr"
; nSize : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "PSAPI.dll" #cfunc global GetDeviceDriverFileNameW "GetDeviceDriverFileNameW" sptr, var, int ; res = GetDeviceDriverFileNameW(ImageBase, lpFilename, nSize) ; ImageBase : void* -> "sptr" ; lpFilename : LPWSTR out -> "var" ; nSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "PSAPI.dll" #cfunc global GetDeviceDriverFileNameW "GetDeviceDriverFileNameW" sptr, sptr, int ; res = GetDeviceDriverFileNameW(ImageBase, varptr(lpFilename), nSize) ; ImageBase : void* -> "sptr" ; lpFilename : LPWSTR out -> "sptr" ; nSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD GetDeviceDriverFileNameW(void* ImageBase, LPWSTR lpFilename, DWORD nSize) #uselib "PSAPI.dll" #cfunc global GetDeviceDriverFileNameW "GetDeviceDriverFileNameW" intptr, var, int ; res = GetDeviceDriverFileNameW(ImageBase, lpFilename, nSize) ; ImageBase : void* -> "intptr" ; lpFilename : LPWSTR out -> "var" ; nSize : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetDeviceDriverFileNameW(void* ImageBase, LPWSTR lpFilename, DWORD nSize) #uselib "PSAPI.dll" #cfunc global GetDeviceDriverFileNameW "GetDeviceDriverFileNameW" intptr, intptr, int ; res = GetDeviceDriverFileNameW(ImageBase, varptr(lpFilename), nSize) ; ImageBase : void* -> "intptr" ; lpFilename : LPWSTR out -> "intptr" ; nSize : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
psapi = windows.NewLazySystemDLL("PSAPI.dll")
procGetDeviceDriverFileNameW = psapi.NewProc("GetDeviceDriverFileNameW")
)
// ImageBase (void*), lpFilename (LPWSTR out), nSize (DWORD)
r1, _, err := procGetDeviceDriverFileNameW.Call(
uintptr(ImageBase),
uintptr(lpFilename),
uintptr(nSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetDeviceDriverFileNameW(
ImageBase: Pointer; // void*
lpFilename: PWideChar; // LPWSTR out
nSize: DWORD // DWORD
): DWORD; stdcall;
external 'PSAPI.dll' name 'GetDeviceDriverFileNameW';result := DllCall("PSAPI\GetDeviceDriverFileNameW"
, "Ptr", ImageBase ; void*
, "Ptr", lpFilename ; LPWSTR out
, "UInt", nSize ; DWORD
, "UInt") ; return: DWORD●GetDeviceDriverFileNameW(ImageBase, lpFilename, nSize) = DLL("PSAPI.dll", "dword GetDeviceDriverFileNameW(void*, char*, dword)")
# 呼び出し: GetDeviceDriverFileNameW(ImageBase, lpFilename, nSize)
# ImageBase : void* -> "void*"
# lpFilename : LPWSTR out -> "char*"
# nSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。