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

PathCchAppend

関数
既存パスの末尾に別のパス要素を追加する。
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 PathCchAppend(
    LPWSTR pszPath,
    UINT_PTR cchPath,
    LPCWSTR pszMore   // optional
);

パラメーター

名前方向説明
pszPathLPWSTRinoutバッファーへのポインター。呼び出し時には元のパスが格納されています。この関数が正常に終了すると、バッファーには元のパスと追加されたパスが格納されます。
cchPathUINT_PTRinpszPath が指すバッファーのサイズ(文字数)。
pszMoreLPCWSTRinoptionalpszPath が指すパスの末尾に追加するパスへのポインター。UNC パスおよび "\?" シーケンスで始まるパスは、完全修飾パスとして受け付けられ認識されます。これらのパスは pszPath が指す文字列に追加されるのではなく、その文字列を置き換えます。

戻り値の型: HRESULT

公式ドキュメント

あるパスを別のパスの末尾に追加します。この関数は、最終的なパスの長さが MAX_PATH に制限される点で PathCchAppendEx と異なります。また、"\"、"\?&quot;、"\?\UNC&quot; のプレフィックスを持つパスを受け付ける点で PathAppend と異なります。

戻り値

この関数が成功した場合は S_OK を返します。それ以外の場合は、次のものを含む HRESULT コードを返します。

戻り値 説明
E_INVALIDARG
pszPath または pszMoreNULL であるか、cchPath が 0 であるか、cchPathPATHCCH_MAX_CCH より大きい場合。
PATHCCH_E_FILENAME_TOO_LONG
結果として得られる文字列が PATHCCH_MAX_CCH を超える場合。
E_OUTOFMEMORY
必要なサイズのバッファーを割り当てられなかった場合。

解説(Remarks)

この関数は、2 つの文字列の間にバックスラッシュがまだ存在しない場合、その間にバックスラッシュを挿入します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

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

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

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

extern "api-ms-win-core-path-l1-1-0" fn PathCchAppend(
    pszPath: [*c]u16, // LPWSTR in/out
    cchPath: usize, // UINT_PTR
    pszMore: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) i32;
proc PathCchAppend(
    pszPath: ptr uint16,  # LPWSTR in/out
    cchPath: uint,  # UINT_PTR
    pszMore: WideCString  # LPCWSTR optional
): int32 {.importc: "PathCchAppend", stdcall, dynlib: "api-ms-win-core-path-l1-1-0.dll".}
pragma(lib, "api-ms-win-core-path-l1-1-0");
extern(Windows)
int PathCchAppend(
    wchar* pszPath,   // LPWSTR in/out
    size_t cchPath,   // UINT_PTR
    const(wchar)* pszMore   // LPCWSTR optional
);
ccall((:PathCchAppend, "api-ms-win-core-path-l1-1-0.dll"), stdcall, Int32,
      (Ptr{UInt16}, Csize_t, Cwstring),
      pszPath, cchPath, pszMore)
# pszPath : LPWSTR in/out -> Ptr{UInt16}
# cchPath : UINT_PTR -> Csize_t
# pszMore : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t PathCchAppend(
    uint16_t* pszPath,
    uintptr_t cchPath,
    const uint16_t* pszMore);
]]
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.PathCchAppend(pszPath, cchPath, pszMore)
-- pszPath : LPWSTR in/out
-- cchPath : UINT_PTR
-- pszMore : LPCWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-path-l1-1-0.dll');
const PathCchAppend = lib.func('__stdcall', 'PathCchAppend', 'int32_t', ['uint16_t *', 'uintptr_t', 'str16']);
// PathCchAppend(pszPath, cchPath, pszMore)
// pszPath : LPWSTR in/out -> 'uint16_t *'
// cchPath : UINT_PTR -> 'uintptr_t'
// pszMore : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("api-ms-win-core-path-l1-1-0.dll", {
  PathCchAppend: { parameters: ["buffer", "usize", "buffer"], result: "i32" },
});
// lib.symbols.PathCchAppend(pszPath, cchPath, pszMore)
// pszPath : LPWSTR in/out -> "buffer"
// cchPath : UINT_PTR -> "usize"
// pszMore : LPCWSTR optional -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t PathCchAppend(
    uint16_t* pszPath,
    size_t cchPath,
    const uint16_t* pszMore);
C, "api-ms-win-core-path-l1-1-0.dll");
// $ffi->PathCchAppend(pszPath, cchPath, pszMore);
// pszPath : LPWSTR in/out
// cchPath : UINT_PTR
// pszMore : LPCWSTR optional
// 構造体/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 PathCchAppend(
        char[] pszPath,   // LPWSTR in/out
        long cchPath,   // UINT_PTR
        WString pszMore   // LPCWSTR optional
    );
}
@[Link("api-ms-win-core-path-l1-1-0")]
lib Libapi-ms-win-core-path-l1-1-0
  fun PathCchAppend = PathCchAppend(
    pszPath : UInt16*,   # LPWSTR in/out
    cchPath : LibC::SizeT,   # UINT_PTR
    pszMore : UInt16*   # LPCWSTR optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PathCchAppendNative = Int32 Function(Pointer<Utf16>, UintPtr, Pointer<Utf16>);
typedef PathCchAppendDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>);
final PathCchAppend = DynamicLibrary.open('api-ms-win-core-path-l1-1-0.dll')
    .lookupFunction<PathCchAppendNative, PathCchAppendDart>('PathCchAppend');
// pszPath : LPWSTR in/out -> Pointer<Utf16>
// cchPath : UINT_PTR -> UintPtr
// pszMore : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PathCchAppend(
  pszPath: PWideChar;   // LPWSTR in/out
  cchPath: NativeUInt;   // UINT_PTR
  pszMore: PWideChar   // LPCWSTR optional
): Integer; stdcall;
  external 'api-ms-win-core-path-l1-1-0.dll' name 'PathCchAppend';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PathCchAppend"
  c_PathCchAppend :: CWString -> CUIntPtr -> CWString -> IO Int32
-- pszPath : LPWSTR in/out -> CWString
-- cchPath : UINT_PTR -> CUIntPtr
-- pszMore : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pathcchappend =
  foreign "PathCchAppend"
    ((ptr uint16_t) @-> size_t @-> (ptr uint16_t) @-> returning int32_t)
(* pszPath : LPWSTR in/out -> (ptr uint16_t) *)
(* cchPath : UINT_PTR -> size_t *)
(* pszMore : LPCWSTR optional -> (ptr uint16_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 ("PathCchAppend" path-cch-append :convention :stdcall) :int32
  (psz-path :pointer)   ; LPWSTR in/out
  (cch-path :uint64)   ; UINT_PTR
  (psz-more (:string :encoding :utf-16le)))   ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PathCchAppend = Win32::API::More->new('api-ms-win-core-path-l1-1-0',
    'int PathCchAppend(LPWSTR pszPath, WPARAM cchPath, LPCWSTR pszMore)');
# my $ret = $PathCchAppend->Call($pszPath, $cchPath, $pszMore);
# pszPath : LPWSTR in/out -> LPWSTR
# cchPath : UINT_PTR -> WPARAM
# pszMore : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API