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