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 | パス文字列へのポインターです。この関数が正常に終了すると、バッファーにはバックスラッシュが追加された文字列が格納されます。この値は NULL であってはなりません。 |
| cchPath | UINT_PTR | in | pszPath が指すバッファーのサイズ(文字数単位)です。 |
| ppszEnd | LPWSTR* | outoptional | この関数が正常に終了すると、文字列末尾の終端 null 文字を指すポインターのアドレスを受け取る値です。 |
| pcchRemaining | UINT_PTR* | outoptional | この関数が正常に終了すると、終端 null 文字を含む、コピー先バッファー内の未使用文字数が設定される値へのポインターです。 |
戻り値の型: HRESULT
公式ドキュメント
パスとして正しい構文にするため、文字列の末尾にバックスラッシュを追加します。(PathCchAddBackslashEx)
戻り値
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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)。const std = @import("std");
extern "api-ms-win-core-path-l1-1-0" fn PathCchAddBackslashEx(
pszPath: [*c]u16, // LPWSTR in/out
cchPath: usize, // UINT_PTR
ppszEnd: [*c][*c]u16, // LPWSTR* optional, out
pcchRemaining: [*c]usize // UINT_PTR* optional, out
) callconv(std.os.windows.WINAPI) i32;proc PathCchAddBackslashEx(
pszPath: ptr uint16, # LPWSTR in/out
cchPath: uint, # UINT_PTR
ppszEnd: ptr WideCString, # LPWSTR* optional, out
pcchRemaining: ptr uint # UINT_PTR* optional, out
): int32 {.importc: "PathCchAddBackslashEx", stdcall, dynlib: "api-ms-win-core-path-l1-1-0.dll".}pragma(lib, "api-ms-win-core-path-l1-1-0");
extern(Windows)
int PathCchAddBackslashEx(
wchar* pszPath, // LPWSTR in/out
size_t cchPath, // UINT_PTR
wchar** ppszEnd, // LPWSTR* optional, out
size_t* pcchRemaining // UINT_PTR* optional, out
);ccall((:PathCchAddBackslashEx, "api-ms-win-core-path-l1-1-0.dll"), stdcall, Int32,
(Ptr{UInt16}, Csize_t, Ptr{Ptr{UInt16}}, Ptr{Csize_t}),
pszPath, cchPath, ppszEnd, pcchRemaining)
# pszPath : LPWSTR in/out -> Ptr{UInt16}
# cchPath : UINT_PTR -> Csize_t
# ppszEnd : LPWSTR* optional, out -> Ptr{Ptr{UInt16}}
# pcchRemaining : UINT_PTR* optional, out -> Ptr{Csize_t}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PathCchAddBackslashEx(
uint16_t* pszPath,
uintptr_t cchPath,
uint16_t** ppszEnd,
uintptr_t* pcchRemaining);
]]
local api-ms-win-core-path-l1-1-0 = ffi.load("api-ms-win-core-path-l1-1-0")
-- api-ms-win-core-path-l1-1-0.PathCchAddBackslashEx(pszPath, cchPath, ppszEnd, pcchRemaining)
-- pszPath : LPWSTR in/out
-- cchPath : UINT_PTR
-- ppszEnd : LPWSTR* optional, out
-- pcchRemaining : UINT_PTR* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-path-l1-1-0.dll');
const PathCchAddBackslashEx = lib.func('__stdcall', 'PathCchAddBackslashEx', 'int32_t', ['uint16_t *', 'uintptr_t', 'void *', 'uintptr_t *']);
// PathCchAddBackslashEx(pszPath, cchPath, ppszEnd, pcchRemaining)
// pszPath : LPWSTR in/out -> 'uint16_t *'
// cchPath : UINT_PTR -> 'uintptr_t'
// ppszEnd : LPWSTR* optional, out -> 'void *'
// pcchRemaining : UINT_PTR* optional, out -> 'uintptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-path-l1-1-0.dll", {
PathCchAddBackslashEx: { parameters: ["buffer", "usize", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.PathCchAddBackslashEx(pszPath, cchPath, ppszEnd, pcchRemaining)
// pszPath : LPWSTR in/out -> "buffer"
// cchPath : UINT_PTR -> "usize"
// ppszEnd : LPWSTR* optional, out -> "pointer"
// pcchRemaining : UINT_PTR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PathCchAddBackslashEx(
uint16_t* pszPath,
size_t cchPath,
uint16_t** ppszEnd,
size_t* pcchRemaining);
C, "api-ms-win-core-path-l1-1-0.dll");
// $ffi->PathCchAddBackslashEx(pszPath, cchPath, ppszEnd, pcchRemaining);
// pszPath : LPWSTR in/out
// cchPath : UINT_PTR
// ppszEnd : LPWSTR* optional, out
// pcchRemaining : UINT_PTR* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Api-ms-win-core-path-l1-1-0 extends StdCallLibrary {
Api-ms-win-core-path-l1-1-0 INSTANCE = Native.load("api-ms-win-core-path-l1-1-0", Api-ms-win-core-path-l1-1-0.class);
int PathCchAddBackslashEx(
char[] pszPath, // LPWSTR in/out
long cchPath, // UINT_PTR
PointerByReference ppszEnd, // LPWSTR* optional, out
LongByReference pcchRemaining // UINT_PTR* optional, out
);
}@[Link("api-ms-win-core-path-l1-1-0")]
lib Libapi-ms-win-core-path-l1-1-0
fun PathCchAddBackslashEx = PathCchAddBackslashEx(
pszPath : UInt16*, # LPWSTR in/out
cchPath : LibC::SizeT, # UINT_PTR
ppszEnd : UInt16**, # LPWSTR* optional, out
pcchRemaining : LibC::SizeT* # UINT_PTR* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PathCchAddBackslashExNative = Int32 Function(Pointer<Utf16>, UintPtr, Pointer<Pointer<Utf16>>, Pointer<UintPtr>);
typedef PathCchAddBackslashExDart = int Function(Pointer<Utf16>, int, Pointer<Pointer<Utf16>>, Pointer<UintPtr>);
final PathCchAddBackslashEx = DynamicLibrary.open('api-ms-win-core-path-l1-1-0.dll')
.lookupFunction<PathCchAddBackslashExNative, PathCchAddBackslashExDart>('PathCchAddBackslashEx');
// pszPath : LPWSTR in/out -> Pointer<Utf16>
// cchPath : UINT_PTR -> UintPtr
// ppszEnd : LPWSTR* optional, out -> Pointer<Pointer<Utf16>>
// pcchRemaining : UINT_PTR* optional, out -> Pointer<UintPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathCchAddBackslashEx"
c_PathCchAddBackslashEx :: CWString -> CUIntPtr -> Ptr CWString -> Ptr CUIntPtr -> IO Int32
-- pszPath : LPWSTR in/out -> CWString
-- cchPath : UINT_PTR -> CUIntPtr
-- ppszEnd : LPWSTR* optional, out -> Ptr CWString
-- pcchRemaining : UINT_PTR* optional, out -> Ptr CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pathcchaddbackslashex =
foreign "PathCchAddBackslashEx"
((ptr uint16_t) @-> size_t @-> (ptr (ptr uint16_t)) @-> (ptr size_t) @-> returning int32_t)
(* pszPath : LPWSTR in/out -> (ptr uint16_t) *)
(* cchPath : UINT_PTR -> size_t *)
(* ppszEnd : LPWSTR* optional, out -> (ptr (ptr uint16_t)) *)
(* pcchRemaining : UINT_PTR* optional, out -> (ptr size_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-path-l1-1-0 (t "api-ms-win-core-path-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-path-l1-1-0)
(cffi:defcfun ("PathCchAddBackslashEx" path-cch-add-backslash-ex :convention :stdcall) :int32
(psz-path :pointer) ; LPWSTR in/out
(cch-path :uint64) ; UINT_PTR
(ppsz-end :pointer) ; LPWSTR* optional, out
(pcch-remaining :pointer)) ; UINT_PTR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PathCchAddBackslashEx = Win32::API::More->new('api-ms-win-core-path-l1-1-0',
'int PathCchAddBackslashEx(LPWSTR pszPath, WPARAM cchPath, LPVOID ppszEnd, LPVOID pcchRemaining)');
# my $ret = $PathCchAddBackslashEx->Call($pszPath, $cchPath, $ppszEnd, $pcchRemaining);
# pszPath : LPWSTR in/out -> LPWSTR
# cchPath : UINT_PTR -> WPARAM
# ppszEnd : LPWSTR* optional, out -> LPVOID
# pcchRemaining : UINT_PTR* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f PathCchAddBackslash — パス末尾に区切りの円記号を安全に追加する。