Win32 API 日本語リファレンス
ホームUI.Shell › PathAllocCanonicalize

PathAllocCanonicalize

関数
パスを正規化し結果バッファを自動確保する。
DLLapi-ms-win-core-path-l1-1-0.dll呼出規約winapi対応OSwindows8.0

シグネチャ

// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>

HRESULT PathAllocCanonicalize(
    LPCWSTR pszPathIn,
    PATHCCH_OPTIONS dwFlags,
    LPWSTR* ppszPathOut
);

パラメーター

名前方向
pszPathInLPCWSTRin
dwFlagsPATHCCH_OPTIONSin
ppszPathOutLPWSTR*out

戻り値の型: HRESULT

各言語での呼び出し定義

// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>

HRESULT PathAllocCanonicalize(
    LPCWSTR pszPathIn,
    PATHCCH_OPTIONS dwFlags,
    LPWSTR* ppszPathOut
);
[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern int PathAllocCanonicalize(
    [MarshalAs(UnmanagedType.LPWStr)] string pszPathIn,   // LPCWSTR
    uint dwFlags,   // PATHCCH_OPTIONS
    IntPtr ppszPathOut   // LPWSTR* out
);
<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathAllocCanonicalize(
    <MarshalAs(UnmanagedType.LPWStr)> pszPathIn As String,   ' LPCWSTR
    dwFlags As UInteger,   ' PATHCCH_OPTIONS
    ppszPathOut As IntPtr   ' LPWSTR* out
) As Integer
End Function
' pszPathIn : LPCWSTR
' dwFlags : PATHCCH_OPTIONS
' ppszPathOut : LPWSTR* out
Declare PtrSafe Function PathAllocCanonicalize Lib "api-ms-win-core-path-l1-1-0" ( _
    ByVal pszPathIn As LongPtr, _
    ByVal dwFlags As Long, _
    ByVal ppszPathOut As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathAllocCanonicalize = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathAllocCanonicalize
PathAllocCanonicalize.restype = ctypes.c_int
PathAllocCanonicalize.argtypes = [
    wintypes.LPCWSTR,  # pszPathIn : LPCWSTR
    wintypes.DWORD,  # dwFlags : PATHCCH_OPTIONS
    ctypes.c_void_p,  # ppszPathOut : LPWSTR* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-path-l1-1-0.dll')
PathAllocCanonicalize = Fiddle::Function.new(
  lib['PathAllocCanonicalize'],
  [
    Fiddle::TYPE_VOIDP,  # pszPathIn : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : PATHCCH_OPTIONS
    Fiddle::TYPE_VOIDP,  # ppszPathOut : LPWSTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-path-l1-1-0")]
extern "system" {
    fn PathAllocCanonicalize(
        pszPathIn: *const u16,  // LPCWSTR
        dwFlags: u32,  // PATHCCH_OPTIONS
        ppszPathOut: *mut *mut u16  // LPWSTR* out
    ) -> 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 PathAllocCanonicalize([MarshalAs(UnmanagedType.LPWStr)] string pszPathIn, uint dwFlags, IntPtr ppszPathOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-path-l1-1-0_PathAllocCanonicalize' -Namespace Win32 -PassThru
# $api::PathAllocCanonicalize(pszPathIn, dwFlags, ppszPathOut)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathAllocCanonicalize "PathAllocCanonicalize" sptr, sptr, sptr
; PathAllocCanonicalize pszPathIn, dwFlags, varptr(ppszPathOut)   ; 戻り値は stat
; pszPathIn : LPCWSTR -> "sptr"
; dwFlags : PATHCCH_OPTIONS -> "sptr"
; ppszPathOut : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathAllocCanonicalize "PathAllocCanonicalize" wstr, int, var
; res = PathAllocCanonicalize(pszPathIn, dwFlags, ppszPathOut)
; pszPathIn : LPCWSTR -> "wstr"
; dwFlags : PATHCCH_OPTIONS -> "int"
; ppszPathOut : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT PathAllocCanonicalize(LPCWSTR pszPathIn, PATHCCH_OPTIONS dwFlags, LPWSTR* ppszPathOut)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathAllocCanonicalize "PathAllocCanonicalize" wstr, int, var
; res = PathAllocCanonicalize(pszPathIn, dwFlags, ppszPathOut)
; pszPathIn : LPCWSTR -> "wstr"
; dwFlags : PATHCCH_OPTIONS -> "int"
; ppszPathOut : LPWSTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。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")
	procPathAllocCanonicalize = api_ms_win_core_path_l1_1_0.NewProc("PathAllocCanonicalize")
)

// pszPathIn (LPCWSTR), dwFlags (PATHCCH_OPTIONS), ppszPathOut (LPWSTR* out)
r1, _, err := procPathAllocCanonicalize.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPathIn))),
	uintptr(dwFlags),
	uintptr(ppszPathOut),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PathAllocCanonicalize(
  pszPathIn: PWideChar;   // LPCWSTR
  dwFlags: DWORD;   // PATHCCH_OPTIONS
  ppszPathOut: PPWideChar   // LPWSTR* out
): Integer; stdcall;
  external 'api-ms-win-core-path-l1-1-0.dll' name 'PathAllocCanonicalize';
result := DllCall("api-ms-win-core-path-l1-1-0\PathAllocCanonicalize"
    , "WStr", pszPathIn   ; LPCWSTR
    , "UInt", dwFlags   ; PATHCCH_OPTIONS
    , "Ptr", ppszPathOut   ; LPWSTR* out
    , "Int")   ; return: HRESULT
●PathAllocCanonicalize(pszPathIn, dwFlags, ppszPathOut) = DLL("api-ms-win-core-path-l1-1-0.dll", "int PathAllocCanonicalize(char*, dword, void*)")
# 呼び出し: PathAllocCanonicalize(pszPathIn, dwFlags, ppszPathOut)
# pszPathIn : LPCWSTR -> "char*"
# dwFlags : PATHCCH_OPTIONS -> "dword"
# ppszPathOut : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。