PathCchCanonicalize
関数パス内の相対要素を解決して正規形に変換する。
シグネチャ
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathCchCanonicalize(
LPWSTR pszPathOut,
UINT_PTR cchPathOut,
LPCWSTR pszPathIn
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszPathOut | LPWSTR | out |
| cchPathOut | UINT_PTR | in |
| pszPathIn | LPCWSTR | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathCchCanonicalize(
LPWSTR pszPathOut,
UINT_PTR cchPathOut,
LPCWSTR pszPathIn
);[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern int PathCchCanonicalize(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPathOut, // LPWSTR out
UIntPtr cchPathOut, // UINT_PTR
[MarshalAs(UnmanagedType.LPWStr)] string pszPathIn // LPCWSTR
);<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathCchCanonicalize(
<MarshalAs(UnmanagedType.LPWStr)> pszPathOut As System.Text.StringBuilder, ' LPWSTR out
cchPathOut As UIntPtr, ' UINT_PTR
<MarshalAs(UnmanagedType.LPWStr)> pszPathIn As String ' LPCWSTR
) As Integer
End Function' pszPathOut : LPWSTR out
' cchPathOut : UINT_PTR
' pszPathIn : LPCWSTR
Declare PtrSafe Function PathCchCanonicalize Lib "api-ms-win-core-path-l1-1-0" ( _
ByVal pszPathOut As LongPtr, _
ByVal cchPathOut As LongPtr, _
ByVal pszPathIn As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PathCchCanonicalize = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathCchCanonicalize
PathCchCanonicalize.restype = ctypes.c_int
PathCchCanonicalize.argtypes = [
wintypes.LPWSTR, # pszPathOut : LPWSTR out
ctypes.c_size_t, # cchPathOut : UINT_PTR
wintypes.LPCWSTR, # pszPathIn : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-path-l1-1-0.dll')
PathCchCanonicalize = Fiddle::Function.new(
lib['PathCchCanonicalize'],
[
Fiddle::TYPE_VOIDP, # pszPathOut : LPWSTR out
Fiddle::TYPE_UINTPTR_T, # cchPathOut : UINT_PTR
Fiddle::TYPE_VOIDP, # pszPathIn : LPCWSTR
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-path-l1-1-0")]
extern "system" {
fn PathCchCanonicalize(
pszPathOut: *mut u16, // LPWSTR out
cchPathOut: usize, // UINT_PTR
pszPathIn: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("api-ms-win-core-path-l1-1-0.dll")]
public static extern int PathCchCanonicalize([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPathOut, UIntPtr cchPathOut, [MarshalAs(UnmanagedType.LPWStr)] string pszPathIn);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-path-l1-1-0_PathCchCanonicalize' -Namespace Win32 -PassThru
# $api::PathCchCanonicalize(pszPathOut, cchPathOut, pszPathIn)#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathCchCanonicalize "PathCchCanonicalize" sptr, sptr, sptr
; PathCchCanonicalize varptr(pszPathOut), cchPathOut, pszPathIn ; 戻り値は stat
; pszPathOut : LPWSTR out -> "sptr"
; cchPathOut : UINT_PTR -> "sptr"
; pszPathIn : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchCanonicalize "PathCchCanonicalize" var, sptr, wstr ; res = PathCchCanonicalize(pszPathOut, cchPathOut, pszPathIn) ; pszPathOut : LPWSTR out -> "var" ; cchPathOut : UINT_PTR -> "sptr" ; pszPathIn : LPCWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchCanonicalize "PathCchCanonicalize" sptr, sptr, wstr ; res = PathCchCanonicalize(varptr(pszPathOut), cchPathOut, pszPathIn) ; pszPathOut : LPWSTR out -> "sptr" ; cchPathOut : UINT_PTR -> "sptr" ; pszPathIn : LPCWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT PathCchCanonicalize(LPWSTR pszPathOut, UINT_PTR cchPathOut, LPCWSTR pszPathIn) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchCanonicalize "PathCchCanonicalize" var, intptr, wstr ; res = PathCchCanonicalize(pszPathOut, cchPathOut, pszPathIn) ; pszPathOut : LPWSTR out -> "var" ; cchPathOut : UINT_PTR -> "intptr" ; pszPathIn : LPCWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT PathCchCanonicalize(LPWSTR pszPathOut, UINT_PTR cchPathOut, LPCWSTR pszPathIn) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchCanonicalize "PathCchCanonicalize" intptr, intptr, wstr ; res = PathCchCanonicalize(varptr(pszPathOut), cchPathOut, pszPathIn) ; pszPathOut : LPWSTR out -> "intptr" ; cchPathOut : UINT_PTR -> "intptr" ; pszPathIn : LPCWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_path_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-path-l1-1-0.dll")
procPathCchCanonicalize = api_ms_win_core_path_l1_1_0.NewProc("PathCchCanonicalize")
)
// pszPathOut (LPWSTR out), cchPathOut (UINT_PTR), pszPathIn (LPCWSTR)
r1, _, err := procPathCchCanonicalize.Call(
uintptr(pszPathOut),
uintptr(cchPathOut),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPathIn))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction PathCchCanonicalize(
pszPathOut: PWideChar; // LPWSTR out
cchPathOut: NativeUInt; // UINT_PTR
pszPathIn: PWideChar // LPCWSTR
): Integer; stdcall;
external 'api-ms-win-core-path-l1-1-0.dll' name 'PathCchCanonicalize';result := DllCall("api-ms-win-core-path-l1-1-0\PathCchCanonicalize"
, "Ptr", pszPathOut ; LPWSTR out
, "UPtr", cchPathOut ; UINT_PTR
, "WStr", pszPathIn ; LPCWSTR
, "Int") ; return: HRESULT●PathCchCanonicalize(pszPathOut, cchPathOut, pszPathIn) = DLL("api-ms-win-core-path-l1-1-0.dll", "int PathCchCanonicalize(char*, int, char*)")
# 呼び出し: PathCchCanonicalize(pszPathOut, cchPathOut, pszPathIn)
# pszPathOut : LPWSTR out -> "char*"
# cchPathOut : UINT_PTR -> "int"
# pszPathIn : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。