PathCchRemoveBackslashEx
関数パス末尾の区切りの円記号を安全に除去する拡張版である。
シグネチャ
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathCchRemoveBackslashEx(
LPWSTR pszPath,
UINT_PTR cchPath,
LPWSTR* ppszEnd, // optional
UINT_PTR* pcchRemaining // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszPath | LPWSTR | inout | パス文字列へのポインター。この関数が正常に終了すると、文字列には末尾のバックスラッシュが削除されたパスが格納されます。末尾のバックスラッシュが見つからなかった場合、文字列は変更されません。 |
| cchPath | UINT_PTR | in | pszPath が指すバッファーのサイズ(文字数)。 |
| ppszEnd | LPWSTR* | outoptional | この関数が正常に終了すると、新しい文字列の終端を指すポインターのアドレスを受け取る値。文字列が "C:" のようなルートパスである場合、ポインターはバックスラッシュを指します。それ以外の場合、ポインターは文字列の終端の null 文字を指します。 |
| pcchRemaining | UINT_PTR* | outoptional | この関数が正常に終了すると、終端の null 文字を含む、宛先バッファー内の未使用文字数を受け取る値へのポインター。文字列が "C:" のようなルートパスである場合、この数にはその文字列内のバックスラッシュが含まれます。 |
戻り値の型: HRESULT
公式ドキュメント
パス文字列の末尾から末尾のバックスラッシュを削除します。この関数は、新しい文字列の終端へのポインターを返し、バッファー内に残っている未使用文字数を報告できる点で PathCchRemoveBackslash と異なります。また、"\"、"\?"、"\?\UNC" のプレフィックスを持つパスを受け付ける点で PathRemoveBackslash と異なります。
戻り値
解説(Remarks)
この関数は、"C:" のようなルートパス文字列からはバックスラッシュを削除しません。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 PathCchRemoveBackslashEx(
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 PathCchRemoveBackslashEx(
[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 PathCchRemoveBackslashEx(
<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 PathCchRemoveBackslashEx 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
PathCchRemoveBackslashEx = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathCchRemoveBackslashEx
PathCchRemoveBackslashEx.restype = ctypes.c_int
PathCchRemoveBackslashEx.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')
PathCchRemoveBackslashEx = Fiddle::Function.new(
lib['PathCchRemoveBackslashEx'],
[
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 PathCchRemoveBackslashEx(
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 PathCchRemoveBackslashEx([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_PathCchRemoveBackslashEx' -Namespace Win32 -PassThru
# $api::PathCchRemoveBackslashEx(pszPath, cchPath, ppszEnd, pcchRemaining)#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathCchRemoveBackslashEx "PathCchRemoveBackslashEx" sptr, sptr, sptr, sptr
; PathCchRemoveBackslashEx 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 PathCchRemoveBackslashEx "PathCchRemoveBackslashEx" var, sptr, var, var ; res = PathCchRemoveBackslashEx(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 PathCchRemoveBackslashEx "PathCchRemoveBackslashEx" sptr, sptr, sptr, sptr ; res = PathCchRemoveBackslashEx(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 PathCchRemoveBackslashEx(LPWSTR pszPath, UINT_PTR cchPath, LPWSTR* ppszEnd, UINT_PTR* pcchRemaining) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchRemoveBackslashEx "PathCchRemoveBackslashEx" var, intptr, var, var ; res = PathCchRemoveBackslashEx(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 PathCchRemoveBackslashEx(LPWSTR pszPath, UINT_PTR cchPath, LPWSTR* ppszEnd, UINT_PTR* pcchRemaining) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchRemoveBackslashEx "PathCchRemoveBackslashEx" intptr, intptr, intptr, intptr ; res = PathCchRemoveBackslashEx(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")
procPathCchRemoveBackslashEx = api_ms_win_core_path_l1_1_0.NewProc("PathCchRemoveBackslashEx")
)
// pszPath (LPWSTR in/out), cchPath (UINT_PTR), ppszEnd (LPWSTR* optional, out), pcchRemaining (UINT_PTR* optional, out)
r1, _, err := procPathCchRemoveBackslashEx.Call(
uintptr(pszPath),
uintptr(cchPath),
uintptr(ppszEnd),
uintptr(pcchRemaining),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction PathCchRemoveBackslashEx(
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 'PathCchRemoveBackslashEx';result := DllCall("api-ms-win-core-path-l1-1-0\PathCchRemoveBackslashEx"
, "Ptr", pszPath ; LPWSTR in/out
, "UPtr", cchPath ; UINT_PTR
, "Ptr", ppszEnd ; LPWSTR* optional, out
, "Ptr", pcchRemaining ; UINT_PTR* optional, out
, "Int") ; return: HRESULT●PathCchRemoveBackslashEx(pszPath, cchPath, ppszEnd, pcchRemaining) = DLL("api-ms-win-core-path-l1-1-0.dll", "int PathCchRemoveBackslashEx(char*, int, void*, void*)")
# 呼び出し: PathCchRemoveBackslashEx(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 PathCchRemoveBackslashEx(
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 PathCchRemoveBackslashEx(
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: "PathCchRemoveBackslashEx", stdcall, dynlib: "api-ms-win-core-path-l1-1-0.dll".}pragma(lib, "api-ms-win-core-path-l1-1-0");
extern(Windows)
int PathCchRemoveBackslashEx(
wchar* pszPath, // LPWSTR in/out
size_t cchPath, // UINT_PTR
wchar** ppszEnd, // LPWSTR* optional, out
size_t* pcchRemaining // UINT_PTR* optional, out
);ccall((:PathCchRemoveBackslashEx, "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 PathCchRemoveBackslashEx(
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.PathCchRemoveBackslashEx(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 PathCchRemoveBackslashEx = lib.func('__stdcall', 'PathCchRemoveBackslashEx', 'int32_t', ['uint16_t *', 'uintptr_t', 'void *', 'uintptr_t *']);
// PathCchRemoveBackslashEx(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", {
PathCchRemoveBackslashEx: { parameters: ["buffer", "usize", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.PathCchRemoveBackslashEx(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 PathCchRemoveBackslashEx(
uint16_t* pszPath,
size_t cchPath,
uint16_t** ppszEnd,
size_t* pcchRemaining);
C, "api-ms-win-core-path-l1-1-0.dll");
// $ffi->PathCchRemoveBackslashEx(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 PathCchRemoveBackslashEx(
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 PathCchRemoveBackslashEx = PathCchRemoveBackslashEx(
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 PathCchRemoveBackslashExNative = Int32 Function(Pointer<Utf16>, UintPtr, Pointer<Pointer<Utf16>>, Pointer<UintPtr>);
typedef PathCchRemoveBackslashExDart = int Function(Pointer<Utf16>, int, Pointer<Pointer<Utf16>>, Pointer<UintPtr>);
final PathCchRemoveBackslashEx = DynamicLibrary.open('api-ms-win-core-path-l1-1-0.dll')
.lookupFunction<PathCchRemoveBackslashExNative, PathCchRemoveBackslashExDart>('PathCchRemoveBackslashEx');
// 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 PathCchRemoveBackslashEx(
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 'PathCchRemoveBackslashEx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathCchRemoveBackslashEx"
c_PathCchRemoveBackslashEx :: 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 pathcchremovebackslashex =
foreign "PathCchRemoveBackslashEx"
((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 ("PathCchRemoveBackslashEx" path-cch-remove-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 $PathCchRemoveBackslashEx = Win32::API::More->new('api-ms-win-core-path-l1-1-0',
'int PathCchRemoveBackslashEx(LPWSTR pszPath, WPARAM cchPath, LPVOID ppszEnd, LPVOID pcchRemaining)');
# my $ret = $PathCchRemoveBackslashEx->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 PathCchRemoveBackslash — パス末尾の区切りの円記号を安全に除去する。