PathCanonicalizeW
関数相対指定を解決しパスを正規形に整える。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL PathCanonicalizeW(
LPWSTR pszBuf,
LPCWSTR pszPath
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszBuf | LPWSTR | out |
| pszPath | LPCWSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
BOOL PathCanonicalizeW(
LPWSTR pszBuf,
LPCWSTR pszPath
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool PathCanonicalizeW(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszBuf, // LPWSTR out
[MarshalAs(UnmanagedType.LPWStr)] string pszPath // LPCWSTR
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function PathCanonicalizeW(
<MarshalAs(UnmanagedType.LPWStr)> pszBuf As System.Text.StringBuilder, ' LPWSTR out
<MarshalAs(UnmanagedType.LPWStr)> pszPath As String ' LPCWSTR
) As Boolean
End Function' pszBuf : LPWSTR out
' pszPath : LPCWSTR
Declare PtrSafe Function PathCanonicalizeW Lib "shlwapi" ( _
ByVal pszBuf As LongPtr, _
ByVal pszPath 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
PathCanonicalizeW = ctypes.windll.shlwapi.PathCanonicalizeW
PathCanonicalizeW.restype = wintypes.BOOL
PathCanonicalizeW.argtypes = [
wintypes.LPWSTR, # pszBuf : LPWSTR out
wintypes.LPCWSTR, # pszPath : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
PathCanonicalizeW = Fiddle::Function.new(
lib['PathCanonicalizeW'],
[
Fiddle::TYPE_VOIDP, # pszBuf : LPWSTR out
Fiddle::TYPE_VOIDP, # pszPath : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shlwapi")]
extern "system" {
fn PathCanonicalizeW(
pszBuf: *mut u16, // LPWSTR out
pszPath: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool PathCanonicalizeW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszBuf, [MarshalAs(UnmanagedType.LPWStr)] string pszPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathCanonicalizeW' -Namespace Win32 -PassThru
# $api::PathCanonicalizeW(pszBuf, pszPath)#uselib "SHLWAPI.dll"
#func global PathCanonicalizeW "PathCanonicalizeW" wptr, wptr
; PathCanonicalizeW varptr(pszBuf), pszPath ; 戻り値は stat
; pszBuf : LPWSTR out -> "wptr"
; pszPath : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global PathCanonicalizeW "PathCanonicalizeW" var, wstr ; res = PathCanonicalizeW(pszBuf, pszPath) ; pszBuf : LPWSTR out -> "var" ; pszPath : LPCWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global PathCanonicalizeW "PathCanonicalizeW" sptr, wstr ; res = PathCanonicalizeW(varptr(pszBuf), pszPath) ; pszBuf : LPWSTR out -> "sptr" ; pszPath : LPCWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL PathCanonicalizeW(LPWSTR pszBuf, LPCWSTR pszPath) #uselib "SHLWAPI.dll" #cfunc global PathCanonicalizeW "PathCanonicalizeW" var, wstr ; res = PathCanonicalizeW(pszBuf, pszPath) ; pszBuf : LPWSTR out -> "var" ; pszPath : LPCWSTR -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL PathCanonicalizeW(LPWSTR pszBuf, LPCWSTR pszPath) #uselib "SHLWAPI.dll" #cfunc global PathCanonicalizeW "PathCanonicalizeW" intptr, wstr ; res = PathCanonicalizeW(varptr(pszBuf), pszPath) ; pszBuf : LPWSTR out -> "intptr" ; pszPath : LPCWSTR -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procPathCanonicalizeW = shlwapi.NewProc("PathCanonicalizeW")
)
// pszBuf (LPWSTR out), pszPath (LPCWSTR)
r1, _, err := procPathCanonicalizeW.Call(
uintptr(pszBuf),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction PathCanonicalizeW(
pszBuf: PWideChar; // LPWSTR out
pszPath: PWideChar // LPCWSTR
): BOOL; stdcall;
external 'SHLWAPI.dll' name 'PathCanonicalizeW';result := DllCall("SHLWAPI\PathCanonicalizeW"
, "Ptr", pszBuf ; LPWSTR out
, "WStr", pszPath ; LPCWSTR
, "Int") ; return: BOOL●PathCanonicalizeW(pszBuf, pszPath) = DLL("SHLWAPI.dll", "bool PathCanonicalizeW(char*, char*)")
# 呼び出し: PathCanonicalizeW(pszBuf, pszPath)
# pszBuf : LPWSTR out -> "char*"
# pszPath : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。