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

GetMappedFileNameA

関数
メモリ領域にマップされたファイル名をANSIで取得する。
DLLPSAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD GetMappedFileNameA(
    HANDLE hProcess,
    void* lpv,
    LPSTR lpFilename,
    DWORD nSize
);

パラメーター

名前方向
hProcessHANDLEin
lpvvoid*in
lpFilenameLPSTRout
nSizeDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetMappedFileNameA(
    HANDLE hProcess,
    void* lpv,
    LPSTR lpFilename,
    DWORD nSize
);
[DllImport("PSAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint GetMappedFileNameA(
    IntPtr hProcess,   // HANDLE
    IntPtr lpv,   // 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 GetMappedFileNameA(
    hProcess As IntPtr,   ' HANDLE
    lpv As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPStr)> lpFilename As System.Text.StringBuilder,   ' LPSTR out
    nSize As UInteger   ' DWORD
) As UInteger
End Function
' hProcess : HANDLE
' lpv : void*
' lpFilename : LPSTR out
' nSize : DWORD
Declare PtrSafe Function GetMappedFileNameA Lib "psapi" ( _
    ByVal hProcess As LongPtr, _
    ByVal lpv 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

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

var (
	psapi = windows.NewLazySystemDLL("PSAPI.dll")
	procGetMappedFileNameA = psapi.NewProc("GetMappedFileNameA")
)

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