PathCchAddBackslash
関数パス末尾に区切りの円記号を安全に追加する。
シグネチャ
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathCchAddBackslash(
LPWSTR pszPath,
UINT_PTR cchPath
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszPath | LPWSTR | inout | パス文字列へのポインター。この関数が正常に戻ると、バッファーにはバックスラッシュが追加された文字列が格納されます。この値は NULL であってはなりません。 |
| cchPath | UINT_PTR | in | pszPath が指すバッファーのサイズ(文字数単位)。 |
戻り値の型: HRESULT
公式ドキュメント
パスの正しい構文を作成するために、文字列の末尾にバックスラッシュを追加します。(PathCchAddBackslash)
戻り値
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 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 方式にも切替可。#uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchAddBackslash "PathCchAddBackslash" sptr, sptr ; res = PathCchAddBackslash(varptr(pszPath), cchPath) ; pszPath : LPWSTR in/out -> "sptr" ; cchPath : UINT_PTR -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; HRESULT PathCchAddBackslash(LPWSTR pszPath, UINT_PTR cchPath) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathCchAddBackslash "PathCchAddBackslash" intptr, intptr ; res = PathCchAddBackslash(varptr(pszPath), cchPath) ; pszPath : LPWSTR in/out -> "intptr" ; cchPath : UINT_PTR -> "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")
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 // HRESULTfunction 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)。const std = @import("std");
extern "api-ms-win-core-path-l1-1-0" fn PathCchAddBackslash(
pszPath: [*c]u16, // LPWSTR in/out
cchPath: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) i32;proc PathCchAddBackslash(
pszPath: ptr uint16, # LPWSTR in/out
cchPath: uint # UINT_PTR
): int32 {.importc: "PathCchAddBackslash", stdcall, dynlib: "api-ms-win-core-path-l1-1-0.dll".}pragma(lib, "api-ms-win-core-path-l1-1-0");
extern(Windows)
int PathCchAddBackslash(
wchar* pszPath, // LPWSTR in/out
size_t cchPath // UINT_PTR
);ccall((:PathCchAddBackslash, "api-ms-win-core-path-l1-1-0.dll"), stdcall, Int32,
(Ptr{UInt16}, Csize_t),
pszPath, cchPath)
# pszPath : LPWSTR in/out -> Ptr{UInt16}
# cchPath : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PathCchAddBackslash(
uint16_t* pszPath,
uintptr_t cchPath);
]]
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.PathCchAddBackslash(pszPath, cchPath)
-- pszPath : LPWSTR in/out
-- cchPath : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-path-l1-1-0.dll');
const PathCchAddBackslash = lib.func('__stdcall', 'PathCchAddBackslash', 'int32_t', ['uint16_t *', 'uintptr_t']);
// PathCchAddBackslash(pszPath, cchPath)
// pszPath : LPWSTR in/out -> 'uint16_t *'
// cchPath : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-path-l1-1-0.dll", {
PathCchAddBackslash: { parameters: ["buffer", "usize"], result: "i32" },
});
// lib.symbols.PathCchAddBackslash(pszPath, cchPath)
// pszPath : LPWSTR in/out -> "buffer"
// cchPath : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PathCchAddBackslash(
uint16_t* pszPath,
size_t cchPath);
C, "api-ms-win-core-path-l1-1-0.dll");
// $ffi->PathCchAddBackslash(pszPath, cchPath);
// pszPath : LPWSTR in/out
// cchPath : UINT_PTR
// 構造体/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 PathCchAddBackslash(
char[] pszPath, // LPWSTR in/out
long cchPath // UINT_PTR
);
}@[Link("api-ms-win-core-path-l1-1-0")]
lib Libapi-ms-win-core-path-l1-1-0
fun PathCchAddBackslash = PathCchAddBackslash(
pszPath : UInt16*, # LPWSTR in/out
cchPath : LibC::SizeT # UINT_PTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PathCchAddBackslashNative = Int32 Function(Pointer<Utf16>, UintPtr);
typedef PathCchAddBackslashDart = int Function(Pointer<Utf16>, int);
final PathCchAddBackslash = DynamicLibrary.open('api-ms-win-core-path-l1-1-0.dll')
.lookupFunction<PathCchAddBackslashNative, PathCchAddBackslashDart>('PathCchAddBackslash');
// pszPath : LPWSTR in/out -> Pointer<Utf16>
// cchPath : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathCchAddBackslash"
c_PathCchAddBackslash :: CWString -> CUIntPtr -> IO Int32
-- pszPath : LPWSTR in/out -> CWString
-- cchPath : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pathcchaddbackslash =
foreign "PathCchAddBackslash"
((ptr uint16_t) @-> size_t @-> returning int32_t)
(* pszPath : LPWSTR in/out -> (ptr uint16_t) *)
(* cchPath : UINT_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 ("PathCchAddBackslash" path-cch-add-backslash :convention :stdcall) :int32
(psz-path :pointer) ; LPWSTR in/out
(cch-path :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PathCchAddBackslash = Win32::API::More->new('api-ms-win-core-path-l1-1-0',
'int PathCchAddBackslash(LPWSTR pszPath, WPARAM cchPath)');
# my $ret = $PathCchAddBackslash->Call($pszPath, $cchPath);
# pszPath : LPWSTR in/out -> LPWSTR
# cchPath : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f PathCchAddBackslashEx — パス末尾に区切りの円記号を安全に追加する拡張版である。