ホーム › Storage.FileSystem › GetLongPathNameTransactedA
GetLongPathNameTransactedA
関数トランザクション内で短いパスを長いパス名へ変換する(ANSI版)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
DWORD GetLongPathNameTransactedA(
LPCSTR lpszShortPath,
LPSTR lpszLongPath, // optional
DWORD cchBuffer,
HANDLE hTransaction
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpszShortPath | LPCSTR | in |
| lpszLongPath | LPSTR | outoptional |
| cchBuffer | DWORD | in |
| hTransaction | HANDLE | in |
戻り値の型: DWORD
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
DWORD GetLongPathNameTransactedA(
LPCSTR lpszShortPath,
LPSTR lpszLongPath, // optional
DWORD cchBuffer,
HANDLE hTransaction
);[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint GetLongPathNameTransactedA(
[MarshalAs(UnmanagedType.LPStr)] string lpszShortPath, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszLongPath, // LPSTR optional, out
uint cchBuffer, // DWORD
IntPtr hTransaction // HANDLE
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetLongPathNameTransactedA(
<MarshalAs(UnmanagedType.LPStr)> lpszShortPath As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpszLongPath As System.Text.StringBuilder, ' LPSTR optional, out
cchBuffer As UInteger, ' DWORD
hTransaction As IntPtr ' HANDLE
) As UInteger
End Function' lpszShortPath : LPCSTR
' lpszLongPath : LPSTR optional, out
' cchBuffer : DWORD
' hTransaction : HANDLE
Declare PtrSafe Function GetLongPathNameTransactedA Lib "kernel32" ( _
ByVal lpszShortPath As String, _
ByVal lpszLongPath As String, _
ByVal cchBuffer As Long, _
ByVal hTransaction As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetLongPathNameTransactedA = ctypes.windll.kernel32.GetLongPathNameTransactedA
GetLongPathNameTransactedA.restype = wintypes.DWORD
GetLongPathNameTransactedA.argtypes = [
wintypes.LPCSTR, # lpszShortPath : LPCSTR
wintypes.LPSTR, # lpszLongPath : LPSTR optional, out
wintypes.DWORD, # cchBuffer : DWORD
wintypes.HANDLE, # hTransaction : HANDLE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetLongPathNameTransactedA = Fiddle::Function.new(
lib['GetLongPathNameTransactedA'],
[
Fiddle::TYPE_VOIDP, # lpszShortPath : LPCSTR
Fiddle::TYPE_VOIDP, # lpszLongPath : LPSTR optional, out
-Fiddle::TYPE_INT, # cchBuffer : DWORD
Fiddle::TYPE_VOIDP, # hTransaction : HANDLE
],
-Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetLongPathNameTransactedA(
lpszShortPath: *const u8, // LPCSTR
lpszLongPath: *mut u8, // LPSTR optional, out
cchBuffer: u32, // DWORD
hTransaction: *mut core::ffi::c_void // HANDLE
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint GetLongPathNameTransactedA([MarshalAs(UnmanagedType.LPStr)] string lpszShortPath, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszLongPath, uint cchBuffer, IntPtr hTransaction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetLongPathNameTransactedA' -Namespace Win32 -PassThru
# $api::GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction)#uselib "KERNEL32.dll"
#func global GetLongPathNameTransactedA "GetLongPathNameTransactedA" sptr, sptr, sptr, sptr
; GetLongPathNameTransactedA lpszShortPath, varptr(lpszLongPath), cchBuffer, hTransaction ; 戻り値は stat
; lpszShortPath : LPCSTR -> "sptr"
; lpszLongPath : LPSTR optional, out -> "sptr"
; cchBuffer : DWORD -> "sptr"
; hTransaction : HANDLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetLongPathNameTransactedA "GetLongPathNameTransactedA" str, var, int, sptr ; res = GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction) ; lpszShortPath : LPCSTR -> "str" ; lpszLongPath : LPSTR optional, out -> "var" ; cchBuffer : DWORD -> "int" ; hTransaction : HANDLE -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetLongPathNameTransactedA "GetLongPathNameTransactedA" str, sptr, int, sptr ; res = GetLongPathNameTransactedA(lpszShortPath, varptr(lpszLongPath), cchBuffer, hTransaction) ; lpszShortPath : LPCSTR -> "str" ; lpszLongPath : LPSTR optional, out -> "sptr" ; cchBuffer : DWORD -> "int" ; hTransaction : HANDLE -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD GetLongPathNameTransactedA(LPCSTR lpszShortPath, LPSTR lpszLongPath, DWORD cchBuffer, HANDLE hTransaction) #uselib "KERNEL32.dll" #cfunc global GetLongPathNameTransactedA "GetLongPathNameTransactedA" str, var, int, intptr ; res = GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction) ; lpszShortPath : LPCSTR -> "str" ; lpszLongPath : LPSTR optional, out -> "var" ; cchBuffer : DWORD -> "int" ; hTransaction : HANDLE -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetLongPathNameTransactedA(LPCSTR lpszShortPath, LPSTR lpszLongPath, DWORD cchBuffer, HANDLE hTransaction) #uselib "KERNEL32.dll" #cfunc global GetLongPathNameTransactedA "GetLongPathNameTransactedA" str, intptr, int, intptr ; res = GetLongPathNameTransactedA(lpszShortPath, varptr(lpszLongPath), cchBuffer, hTransaction) ; lpszShortPath : LPCSTR -> "str" ; lpszLongPath : LPSTR optional, out -> "intptr" ; cchBuffer : DWORD -> "int" ; hTransaction : HANDLE -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetLongPathNameTransactedA = kernel32.NewProc("GetLongPathNameTransactedA")
)
// lpszShortPath (LPCSTR), lpszLongPath (LPSTR optional, out), cchBuffer (DWORD), hTransaction (HANDLE)
r1, _, err := procGetLongPathNameTransactedA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszShortPath))),
uintptr(lpszLongPath),
uintptr(cchBuffer),
uintptr(hTransaction),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetLongPathNameTransactedA(
lpszShortPath: PAnsiChar; // LPCSTR
lpszLongPath: PAnsiChar; // LPSTR optional, out
cchBuffer: DWORD; // DWORD
hTransaction: THandle // HANDLE
): DWORD; stdcall;
external 'KERNEL32.dll' name 'GetLongPathNameTransactedA';result := DllCall("KERNEL32\GetLongPathNameTransactedA"
, "AStr", lpszShortPath ; LPCSTR
, "Ptr", lpszLongPath ; LPSTR optional, out
, "UInt", cchBuffer ; DWORD
, "Ptr", hTransaction ; HANDLE
, "UInt") ; return: DWORD●GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction) = DLL("KERNEL32.dll", "dword GetLongPathNameTransactedA(char*, char*, dword, void*)")
# 呼び出し: GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction)
# lpszShortPath : LPCSTR -> "char*"
# lpszLongPath : LPSTR optional, out -> "char*"
# cchBuffer : DWORD -> "dword"
# hTransaction : HANDLE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。