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

PathCchAddBackslash

関数
パス末尾に区切りの円記号を安全に追加する。
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 PathCchAddBackslash(
    LPWSTR pszPath,
    UINT_PTR cchPath
);

パラメーター

名前方向
pszPathLPWSTRinout
cchPathUINT_PTRin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT PathCchAddBackslash(
    LPWSTR pszPath,
    UINT_PTR cchPath
);
[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern int PathCchAddBackslash(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath,   // LPWSTR in/out
    UIntPtr cchPath   // UINT_PTR
);
<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathCchAddBackslash(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As System.Text.StringBuilder,   ' LPWSTR in/out
    cchPath As UIntPtr   ' UINT_PTR
) As Integer
End Function
' pszPath : LPWSTR in/out
' cchPath : UINT_PTR
Declare PtrSafe Function PathCchAddBackslash Lib "api-ms-win-core-path-l1-1-0" ( _
    ByVal pszPath As LongPtr, _
    ByVal cchPath As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathCchAddBackslash = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathCchAddBackslash
PathCchAddBackslash.restype = ctypes.c_int
PathCchAddBackslash.argtypes = [
    wintypes.LPWSTR,  # pszPath : LPWSTR in/out
    ctypes.c_size_t,  # cchPath : UINT_PTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-path-l1-1-0.dll')
PathCchAddBackslash = Fiddle::Function.new(
  lib['PathCchAddBackslash'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPWSTR in/out
    Fiddle::TYPE_UINTPTR_T,  # cchPath : UINT_PTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-path-l1-1-0")]
extern "system" {
    fn PathCchAddBackslash(
        pszPath: *mut u16,  // LPWSTR in/out
        cchPath: usize  // UINT_PTR
    ) -> 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 PathCchAddBackslash([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath, UIntPtr cchPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-path-l1-1-0_PathCchAddBackslash' -Namespace Win32 -PassThru
# $api::PathCchAddBackslash(pszPath, cchPath)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathCchAddBackslash "PathCchAddBackslash" sptr, sptr
; PathCchAddBackslash varptr(pszPath), cchPath   ; 戻り値は stat
; pszPath : LPWSTR in/out -> "sptr"
; cchPath : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathCchAddBackslash "PathCchAddBackslash" var, sptr
; res = PathCchAddBackslash(pszPath, cchPath)
; pszPath : LPWSTR in/out -> "var"
; cchPath : UINT_PTR -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT PathCchAddBackslash(LPWSTR pszPath, UINT_PTR cchPath)
#uselib "api-ms-win-core-path-l1-1-0.dll"
#cfunc global PathCchAddBackslash "PathCchAddBackslash" var, intptr
; res = PathCchAddBackslash(pszPath, cchPath)
; pszPath : LPWSTR in/out -> "var"
; cchPath : UINT_PTR -> "intptr"
; ※出力/バッファ引数は 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")
	procPathCchAddBackslash = api_ms_win_core_path_l1_1_0.NewProc("PathCchAddBackslash")
)

// pszPath (LPWSTR in/out), cchPath (UINT_PTR)
r1, _, err := procPathCchAddBackslash.Call(
	uintptr(pszPath),
	uintptr(cchPath),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PathCchAddBackslash(
  pszPath: PWideChar;   // LPWSTR in/out
  cchPath: NativeUInt   // UINT_PTR
): Integer; stdcall;
  external 'api-ms-win-core-path-l1-1-0.dll' name 'PathCchAddBackslash';
result := DllCall("api-ms-win-core-path-l1-1-0\PathCchAddBackslash"
    , "Ptr", pszPath   ; LPWSTR in/out
    , "UPtr", cchPath   ; UINT_PTR
    , "Int")   ; return: HRESULT
●PathCchAddBackslash(pszPath, cchPath) = DLL("api-ms-win-core-path-l1-1-0.dll", "int PathCchAddBackslash(char*, int)")
# 呼び出し: PathCchAddBackslash(pszPath, cchPath)
# pszPath : LPWSTR in/out -> "char*"
# cchPath : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。