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