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