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