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