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

PathCchAppendEx

関数
オプション指定でパス末尾に別のパスを追加する。
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 PathCchAppendEx(
    LPWSTR pszPath,
    UINT_PTR cchPath,
    LPCWSTR pszMore,   // optional
    PATHCCH_OPTIONS dwFlags
);

パラメーター

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

次のフラグのうち 1 つ以上です。

意味
PATHCCH_NONE
0x0000000
MAX_PATH より長い \\?\ パス(つまりロングパス)の構築を許可しません。
PATHCCH_ALLOW_LONG_PATHS
0x00000001
MAX_PATH より長い \\?\ パスの構築を許可します。
PATHCCH_FORCE_ENABLE_LONG_NAME_PROCESS
0x00000002
プロセスのロングネーム有効状態とは無関係に、呼び出し元をロングパス有効として扱うよう API に強制します。このオプションは PATHCCH_ALLOW_LONG_PATHS が指定されている場合にのみ使用でき、PATHCCH_FORCE_DISABLE_LONG_NAME_PROCESS と併用することはできません。

注意 この値は Windows 10 バージョン 1703 以降で使用できます。

PATHCCH_FORCE_DISABLE_LONG_NAME_PROCESS
0x00000004
プロセスのロングネーム有効状態とは無関係に、呼び出し元をロングパス無効として扱うよう API に強制します。このオプションは PATHCCH_ALLOW_LONG_PATHS が指定されている場合にのみ使用でき、PATHCCH_FORCE_ENABLE_LONG_NAME_PROCESS と併用することはできません。

注意 この値は Windows 10 バージョン 1703 以降で使用できます。

PATHCCH_DO_NOT_NORMALIZE_SEGMENTS
0x00000008
末尾のドットおよびスペースの除去を含む、パスセグメントの正規化を無効にします。これにより、win32 のパス正規化によってブロックされるパスへのアクセスが可能になります。

注意 この値は Windows 10 バージョン 1703 以降で使用できます。

PATHCCH_ENSURE_IS_EXTENDED_LENGTH_PATH
0x00000010
入力パスがまだ拡張長 DOS デバイスパス形式(\\?\ プレフィックス付き)でない場合に、その形式へ変換します。これにより、Win32 の正規化規則(末尾のドットやスペースを除去することがあります)やパス長の制限のために本来アドレス指定できないパスへのアクセスが可能になります。このオプションは PATHCCH_DO_NOT_NORMALIZE_SEGMENTS と同じ動作を含みます。

注意 この値は Windows 10 バージョン 1703 以降で使用できます。

戻り値の型: HRESULT

公式ドキュメント

あるパスを別のパスの末尾に追加します。この関数は、より長い最終パスを構築できる点で PathCchAppend とは異なります。また、"\"、"\?&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 PathCchAppendEx(
    LPWSTR pszPath,
    UINT_PTR cchPath,
    LPCWSTR pszMore,   // optional
    PATHCCH_OPTIONS dwFlags
);
[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern int PathCchAppendEx(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszPath,   // LPWSTR in/out
    UIntPtr cchPath,   // UINT_PTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszMore,   // LPCWSTR optional
    uint dwFlags   // PATHCCH_OPTIONS
);
<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathCchAppendEx(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As System.Text.StringBuilder,   ' LPWSTR in/out
    cchPath As UIntPtr,   ' UINT_PTR
    <MarshalAs(UnmanagedType.LPWStr)> pszMore As String,   ' LPCWSTR optional
    dwFlags As UInteger   ' PATHCCH_OPTIONS
) As Integer
End Function
' pszPath : LPWSTR in/out
' cchPath : UINT_PTR
' pszMore : LPCWSTR optional
' dwFlags : PATHCCH_OPTIONS
Declare PtrSafe Function PathCchAppendEx Lib "api-ms-win-core-path-l1-1-0" ( _
    ByVal pszPath As LongPtr, _
    ByVal cchPath As LongPtr, _
    ByVal pszMore As LongPtr, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

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

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

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

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

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

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

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

関連項目

類似 API
使用する型