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

GetLongPathNameA

関数
短い形式のパスを長い形式のパスに変換する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD GetLongPathNameA(
    LPCSTR lpszShortPath,
    LPSTR lpszLongPath,   // optional
    DWORD cchBuffer
);

パラメーター

名前方向
lpszShortPathLPCSTRin
lpszLongPathLPSTRoutoptional
cchBufferDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

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

GetLongPathNameA = ctypes.windll.kernel32.GetLongPathNameA
GetLongPathNameA.restype = wintypes.DWORD
GetLongPathNameA.argtypes = [
    wintypes.LPCSTR,  # lpszShortPath : LPCSTR
    wintypes.LPSTR,  # lpszLongPath : LPSTR optional, out
    wintypes.DWORD,  # cchBuffer : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetLongPathNameA = kernel32.NewProc("GetLongPathNameA")
)

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