GetLongPathNameTransactedA
関数シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
DWORD GetLongPathNameTransactedA(
LPCSTR lpszShortPath,
LPSTR lpszLongPath, // optional
DWORD cchBuffer,
HANDLE hTransaction
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpszShortPath | LPCSTR | in | 変換するパス。 既定では、名前は MAX_PATH 文字に制限されます。この制限を 32,767 ワイド文字まで拡張するには、パスの先頭に "\\?\" を付加します。詳細については、「ファイル、パス、および名前空間の名前付け」を参照してください。 ヒント
Windows 10 バージョン 1607 以降では、"\\?\" を付加せずに MAX_PATH 制限を解除するようオプトインできます。詳細については、「ファイル、パス、および名前空間の名前付け」の「Maximum Path Length Limitation」セクションを参照してください。 パスはローカルコンピューター上に存在する必要があります。そうでない場合、関数は失敗し、最終エラーコードは ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE に設定されます。 |
| lpszLongPath | LPSTR | outoptional | 長いパスを受け取るバッファーへのポインター。 lpszShortPath パラメーターに使用したバッファーと同じものを使用できます。 |
| cchBuffer | DWORD | in | lpszLongPath が指すバッファーのサイズ( TCHAR 単位)。 |
| hTransaction | HANDLE | in | トランザクションへのハンドル。このハンドルは CreateTransaction 関数によって返されます。 |
戻り値の型: DWORD
公式ドキュメント
指定されたパスをトランザクション操作として長い形式に変換します。(ANSI)
戻り値
関数が成功した場合、戻り値は lpszLongPath にコピーされた文字列の長さ(TCHAR 単位)で、終端の null 文字は含まれません。
lpBuffer バッファーがパスを格納するには小さすぎる場合、戻り値はパスと終端の null 文字を格納するために必要なバッファーのサイズ(TCHAR 単位)です。
ファイルが存在しない場合など、その他の理由で関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
多くのファイルシステムでは、短いファイル名にはチルダ()文字が含まれます。ただし、すべてのファイルシステムがこの規則に従うわけではありません。したがって、パスにチルダ()文字が含まれていないからといって、
GetLongPathNameTransacted の呼び出しを省略できると想定しないでください。
長いパスが見つからない場合、この関数は lpszShortPath パラメーターで指定された名前を lpszLongPath パラメーターに返します。
戻り値が cchBuffer で指定された値より大きい場合、パスを格納するのに十分な大きさのバッファーを使用して関数を再度呼び出すことができます。この場合の例については、GetFullPathName のサンプルコードのセクションを参照してください。
Windows 8 および Windows Server 2012 では、この関数は次のテクノロジによってサポートされます。
| テクノロジ | サポート |
|---|---|
| Server Message Block (SMB) 3.0 プロトコル | いいえ |
| SMB 3.0 Transparent Failover (TFO) | いいえ |
| SMB 3.0 with Scale-out File Shares (SO) | いいえ |
| Cluster Shared Volume File System (CsvFS) | いいえ |
| Resilient File System (ReFS) | いいえ |
SMB 3.0 は TxF をサポートしません。
winbase.h ヘッダーは、GetLongPathNameTransacted を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存でないコードと混在させると、不一致が生じ、コンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、「関数プロトタイプの規則」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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)。const std = @import("std");
extern "kernel32" fn GetLongPathNameTransactedA(
lpszShortPath: [*c]const u8, // LPCSTR
lpszLongPath: [*c]u8, // LPSTR optional, out
cchBuffer: u32, // DWORD
hTransaction: ?*anyopaque // HANDLE
) callconv(std.os.windows.WINAPI) u32;proc GetLongPathNameTransactedA(
lpszShortPath: cstring, # LPCSTR
lpszLongPath: ptr char, # LPSTR optional, out
cchBuffer: uint32, # DWORD
hTransaction: pointer # HANDLE
): uint32 {.importc: "GetLongPathNameTransactedA", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
uint GetLongPathNameTransactedA(
const(char)* lpszShortPath, // LPCSTR
char* lpszLongPath, // LPSTR optional, out
uint cchBuffer, // DWORD
void* hTransaction // HANDLE
);ccall((:GetLongPathNameTransactedA, "KERNEL32.dll"), stdcall, UInt32,
(Cstring, Ptr{UInt8}, UInt32, Ptr{Cvoid}),
lpszShortPath, lpszLongPath, cchBuffer, hTransaction)
# lpszShortPath : LPCSTR -> Cstring
# lpszLongPath : LPSTR optional, out -> Ptr{UInt8}
# cchBuffer : DWORD -> UInt32
# hTransaction : HANDLE -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetLongPathNameTransactedA(
const char* lpszShortPath,
char* lpszLongPath,
uint32_t cchBuffer,
void* hTransaction);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction)
-- lpszShortPath : LPCSTR
-- lpszLongPath : LPSTR optional, out
-- cchBuffer : DWORD
-- hTransaction : HANDLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetLongPathNameTransactedA = lib.func('__stdcall', 'GetLongPathNameTransactedA', 'uint32_t', ['str', 'char *', 'uint32_t', 'void *']);
// GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction)
// lpszShortPath : LPCSTR -> 'str'
// lpszLongPath : LPSTR optional, out -> 'char *'
// cchBuffer : DWORD -> 'uint32_t'
// hTransaction : HANDLE -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetLongPathNameTransactedA: { parameters: ["buffer", "buffer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction)
// lpszShortPath : LPCSTR -> "buffer"
// lpszLongPath : LPSTR optional, out -> "buffer"
// cchBuffer : DWORD -> "u32"
// hTransaction : HANDLE -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetLongPathNameTransactedA(
const char* lpszShortPath,
char* lpszLongPath,
uint32_t cchBuffer,
void* hTransaction);
C, "KERNEL32.dll");
// $ffi->GetLongPathNameTransactedA(lpszShortPath, lpszLongPath, cchBuffer, hTransaction);
// lpszShortPath : LPCSTR
// lpszLongPath : LPSTR optional, out
// cchBuffer : DWORD
// hTransaction : HANDLE
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.ASCII_OPTIONS);
int GetLongPathNameTransactedA(
String lpszShortPath, // LPCSTR
byte[] lpszLongPath, // LPSTR optional, out
int cchBuffer, // DWORD
Pointer hTransaction // HANDLE
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetLongPathNameTransactedA = GetLongPathNameTransactedA(
lpszShortPath : UInt8*, # LPCSTR
lpszLongPath : UInt8*, # LPSTR optional, out
cchBuffer : UInt32, # DWORD
hTransaction : Void* # HANDLE
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetLongPathNameTransactedANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Void>);
typedef GetLongPathNameTransactedADart = int Function(Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Void>);
final GetLongPathNameTransactedA = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetLongPathNameTransactedANative, GetLongPathNameTransactedADart>('GetLongPathNameTransactedA');
// lpszShortPath : LPCSTR -> Pointer<Utf8>
// lpszLongPath : LPSTR optional, out -> Pointer<Utf8>
// cchBuffer : DWORD -> Uint32
// hTransaction : HANDLE -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetLongPathNameTransactedA(
lpszShortPath: PAnsiChar; // LPCSTR
lpszLongPath: PAnsiChar; // LPSTR optional, out
cchBuffer: DWORD; // DWORD
hTransaction: THandle // HANDLE
): DWORD; stdcall;
external 'KERNEL32.dll' name 'GetLongPathNameTransactedA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetLongPathNameTransactedA"
c_GetLongPathNameTransactedA :: CString -> CString -> Word32 -> Ptr () -> IO Word32
-- lpszShortPath : LPCSTR -> CString
-- lpszLongPath : LPSTR optional, out -> CString
-- cchBuffer : DWORD -> Word32
-- hTransaction : HANDLE -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getlongpathnametransacteda =
foreign "GetLongPathNameTransactedA"
(string @-> string @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* lpszShortPath : LPCSTR -> string *)
(* lpszLongPath : LPSTR optional, out -> string *)
(* cchBuffer : DWORD -> uint32_t *)
(* hTransaction : HANDLE -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetLongPathNameTransactedA" get-long-path-name-transacted-a :convention :stdcall) :uint32
(lpsz-short-path :string) ; LPCSTR
(lpsz-long-path :pointer) ; LPSTR optional, out
(cch-buffer :uint32) ; DWORD
(h-transaction :pointer)) ; HANDLE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetLongPathNameTransactedA = Win32::API::More->new('KERNEL32',
'DWORD GetLongPathNameTransactedA(LPCSTR lpszShortPath, LPSTR lpszLongPath, DWORD cchBuffer, HANDLE hTransaction)');
# my $ret = $GetLongPathNameTransactedA->Call($lpszShortPath, $lpszLongPath, $cchBuffer, $hTransaction);
# lpszShortPath : LPCSTR -> LPCSTR
# lpszLongPath : LPSTR optional, out -> LPSTR
# cchBuffer : DWORD -> DWORD
# hTransaction : HANDLE -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetLongPathNameTransactedW (Unicode版) — トランザクション内で短いパスを長いパス名へ変換する(Unicode版)。
- f GetFullPathNameTransactedA — トランザクション内でファイルの完全パス名を取得する(ANSI版)。
- f GetShortPathNameA — 長いパス名を8.3形式の短いパス名へ変換する(ANSI版)。