Win32 API 日本語リファレンス
ホームStorage.FileSystem › GetFullPathNameA

GetFullPathNameA

関数
相対パスを絶対パスに変換して取得する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD GetFullPathNameA(
    LPCSTR lpFileName,
    DWORD nBufferLength,
    LPSTR lpBuffer,   // optional
    LPSTR* lpFilePart   // optional
);

パラメーター

名前方向
lpFileNameLPCSTRin
nBufferLengthDWORDin
lpBufferLPSTRoutoptional
lpFilePartLPSTR*outoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

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

GetFullPathNameA = ctypes.windll.kernel32.GetFullPathNameA
GetFullPathNameA.restype = wintypes.DWORD
GetFullPathNameA.argtypes = [
    wintypes.LPCSTR,  # lpFileName : LPCSTR
    wintypes.DWORD,  # nBufferLength : DWORD
    wintypes.LPSTR,  # lpBuffer : LPSTR optional, out
    ctypes.c_void_p,  # lpFilePart : LPSTR* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetFullPathNameA = Fiddle::Function.new(
  lib['GetFullPathNameA'],
  [
    Fiddle::TYPE_VOIDP,  # lpFileName : LPCSTR
    -Fiddle::TYPE_INT,  # nBufferLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpBuffer : LPSTR optional, out
    Fiddle::TYPE_VOIDP,  # lpFilePart : LPSTR* optional, out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetFullPathNameA(
        lpFileName: *const u8,  // LPCSTR
        nBufferLength: u32,  // DWORD
        lpBuffer: *mut u8,  // LPSTR optional, out
        lpFilePart: *mut *mut u8  // LPSTR* optional, out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint GetFullPathNameA([MarshalAs(UnmanagedType.LPStr)] string lpFileName, uint nBufferLength, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpBuffer, IntPtr lpFilePart);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetFullPathNameA' -Namespace Win32 -PassThru
# $api::GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, lpFilePart)
#uselib "KERNEL32.dll"
#func global GetFullPathNameA "GetFullPathNameA" sptr, sptr, sptr, sptr
; GetFullPathNameA lpFileName, nBufferLength, varptr(lpBuffer), varptr(lpFilePart)   ; 戻り値は stat
; lpFileName : LPCSTR -> "sptr"
; nBufferLength : DWORD -> "sptr"
; lpBuffer : LPSTR optional, out -> "sptr"
; lpFilePart : LPSTR* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global GetFullPathNameA "GetFullPathNameA" str, int, var, var
; res = GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, lpFilePart)
; lpFileName : LPCSTR -> "str"
; nBufferLength : DWORD -> "int"
; lpBuffer : LPSTR optional, out -> "var"
; lpFilePart : LPSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetFullPathNameA(LPCSTR lpFileName, DWORD nBufferLength, LPSTR lpBuffer, LPSTR* lpFilePart)
#uselib "KERNEL32.dll"
#cfunc global GetFullPathNameA "GetFullPathNameA" str, int, var, var
; res = GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, lpFilePart)
; lpFileName : LPCSTR -> "str"
; nBufferLength : DWORD -> "int"
; lpBuffer : LPSTR optional, out -> "var"
; lpFilePart : LPSTR* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetFullPathNameA = kernel32.NewProc("GetFullPathNameA")
)

// lpFileName (LPCSTR), nBufferLength (DWORD), lpBuffer (LPSTR optional, out), lpFilePart (LPSTR* optional, out)
r1, _, err := procGetFullPathNameA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFileName))),
	uintptr(nBufferLength),
	uintptr(lpBuffer),
	uintptr(lpFilePart),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetFullPathNameA(
  lpFileName: PAnsiChar;   // LPCSTR
  nBufferLength: DWORD;   // DWORD
  lpBuffer: PAnsiChar;   // LPSTR optional, out
  lpFilePart: PPAnsiChar   // LPSTR* optional, out
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'GetFullPathNameA';
result := DllCall("KERNEL32\GetFullPathNameA"
    , "AStr", lpFileName   ; LPCSTR
    , "UInt", nBufferLength   ; DWORD
    , "Ptr", lpBuffer   ; LPSTR optional, out
    , "Ptr", lpFilePart   ; LPSTR* optional, out
    , "UInt")   ; return: DWORD
●GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, lpFilePart) = DLL("KERNEL32.dll", "dword GetFullPathNameA(char*, dword, char*, void*)")
# 呼び出し: GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, lpFilePart)
# lpFileName : LPCSTR -> "char*"
# nBufferLength : DWORD -> "dword"
# lpBuffer : LPSTR optional, out -> "char*"
# lpFilePart : LPSTR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。