Win32 API 日本語リファレンス
ホームSystem.ProcessStatus › GetDeviceDriverFileNameA

GetDeviceDriverFileNameA

関数
デバイスドライバのファイルパスをANSIで取得する。
DLLPSAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD GetDeviceDriverFileNameA(
    void* ImageBase,
    LPSTR lpFilename,
    DWORD nSize
);

パラメーター

名前方向
ImageBasevoid*in
lpFilenameLPSTRout
nSizeDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetDeviceDriverFileNameA(
    void* ImageBase,
    LPSTR lpFilename,
    DWORD nSize
);
[DllImport("PSAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint GetDeviceDriverFileNameA(
    IntPtr ImageBase,   // void*
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpFilename,   // LPSTR out
    uint nSize   // DWORD
);
<DllImport("PSAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetDeviceDriverFileNameA(
    ImageBase As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPStr)> lpFilename As System.Text.StringBuilder,   ' LPSTR out
    nSize As UInteger   ' DWORD
) As UInteger
End Function
' ImageBase : void*
' lpFilename : LPSTR out
' nSize : DWORD
Declare PtrSafe Function GetDeviceDriverFileNameA Lib "psapi" ( _
    ByVal ImageBase As LongPtr, _
    ByVal lpFilename As String, _
    ByVal nSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetDeviceDriverFileNameA = ctypes.windll.psapi.GetDeviceDriverFileNameA
GetDeviceDriverFileNameA.restype = wintypes.DWORD
GetDeviceDriverFileNameA.argtypes = [
    ctypes.POINTER(None),  # ImageBase : void*
    wintypes.LPSTR,  # lpFilename : LPSTR 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')
GetDeviceDriverFileNameA = Fiddle::Function.new(
  lib['GetDeviceDriverFileNameA'],
  [
    Fiddle::TYPE_VOIDP,  # ImageBase : void*
    Fiddle::TYPE_VOIDP,  # lpFilename : LPSTR out
    -Fiddle::TYPE_INT,  # nSize : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "psapi")]
extern "system" {
    fn GetDeviceDriverFileNameA(
        ImageBase: *mut (),  // void*
        lpFilename: *mut u8,  // LPSTR out
        nSize: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("PSAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint GetDeviceDriverFileNameA(IntPtr ImageBase, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpFilename, uint nSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'PSAPI_GetDeviceDriverFileNameA' -Namespace Win32 -PassThru
# $api::GetDeviceDriverFileNameA(ImageBase, lpFilename, nSize)
#uselib "PSAPI.dll"
#func global GetDeviceDriverFileNameA "GetDeviceDriverFileNameA" sptr, sptr, sptr
; GetDeviceDriverFileNameA ImageBase, varptr(lpFilename), nSize   ; 戻り値は stat
; ImageBase : void* -> "sptr"
; lpFilename : LPSTR out -> "sptr"
; nSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "PSAPI.dll"
#cfunc global GetDeviceDriverFileNameA "GetDeviceDriverFileNameA" sptr, var, int
; res = GetDeviceDriverFileNameA(ImageBase, lpFilename, nSize)
; ImageBase : void* -> "sptr"
; lpFilename : LPSTR out -> "var"
; nSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetDeviceDriverFileNameA(void* ImageBase, LPSTR lpFilename, DWORD nSize)
#uselib "PSAPI.dll"
#cfunc global GetDeviceDriverFileNameA "GetDeviceDriverFileNameA" intptr, var, int
; res = GetDeviceDriverFileNameA(ImageBase, lpFilename, nSize)
; ImageBase : void* -> "intptr"
; lpFilename : LPSTR out -> "var"
; nSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	psapi = windows.NewLazySystemDLL("PSAPI.dll")
	procGetDeviceDriverFileNameA = psapi.NewProc("GetDeviceDriverFileNameA")
)

// ImageBase (void*), lpFilename (LPSTR out), nSize (DWORD)
r1, _, err := procGetDeviceDriverFileNameA.Call(
	uintptr(ImageBase),
	uintptr(lpFilename),
	uintptr(nSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetDeviceDriverFileNameA(
  ImageBase: Pointer;   // void*
  lpFilename: PAnsiChar;   // LPSTR out
  nSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'PSAPI.dll' name 'GetDeviceDriverFileNameA';
result := DllCall("PSAPI\GetDeviceDriverFileNameA"
    , "Ptr", ImageBase   ; void*
    , "Ptr", lpFilename   ; LPSTR out
    , "UInt", nSize   ; DWORD
    , "UInt")   ; return: DWORD
●GetDeviceDriverFileNameA(ImageBase, lpFilename, nSize) = DLL("PSAPI.dll", "dword GetDeviceDriverFileNameA(void*, char*, dword)")
# 呼び出し: GetDeviceDriverFileNameA(ImageBase, lpFilename, nSize)
# ImageBase : void* -> "void*"
# lpFilename : LPSTR out -> "char*"
# nSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。