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

PathAppendA

関数
パスに別のパス要素を連結する。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL PathAppendA(
    LPSTR pszPath,
    LPCSTR pszMore
);

パラメーター

名前方向説明
pszPathLPSTRinoutpszMore で指定されたパスが追加される、null 終端文字列へのポインターです。返される文字列を格納するのに十分な大きさを確保するため、このバッファーのサイズは MAX_PATH に設定する必要があります。
pszMoreLPCSTRin追加するパスを格納した、最大長 MAX_PATH の null 終端文字列へのポインターです。

戻り値の型: BOOL

公式ドキュメント

あるパスの末尾に別のパスを追加します。(ANSI)

戻り値

型: BOOL

成功した場合は TRUE を、それ以外の場合は FALSE を返します。

解説(Remarks)

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

pszPath に指定するパスは、相対パス文字列を生成するための "..\" や ".\" で始めることはできません。これらが存在する場合、それらのピリオドは出力文字列から取り除かれます。たとえば、"..\path1\path2" に "path3" を追加すると、出力は "..\path1\path2\path3" ではなく "\path1\path2\path3" になります。


#include <windows.h>
#include <iostream>
#include "Shlwapi.h"

using namespace std;

int main( void )
{
    // String for path name.
    char buffer_1[MAX_PATH] = "name_1\\name_2";
    char *lpStr1;
    lpStr1 = buffer_1;

    // String of what is being added.
    char buffer_2[ ] = "name_3";
    char *lpStr2;
    lpStr2 = buffer_2;

    cout << "The original path string is    " << lpStr1 << endl;
    cout << "The part to append to end is   " << lpStr2 << endl;
    bool ret = PathAppend(lpStr1,lpStr2);
    cout << "The appended path string is    " << lpStr1 << endl;
}

OUTPUT:
--------- 
The original path string is    name_1\name_2
The part to append to end is   name_3
The appended path string is    name_1\name_2\name_3
メモ

shlwapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして PathAppend を定義しています。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、関数プロトタイプの規則 を参照してください。

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

各言語での呼び出し定義

// SHLWAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL PathAppendA(
    LPSTR pszPath,
    LPCSTR pszMore
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool PathAppendA(
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszPath,   // LPSTR in/out
    [MarshalAs(UnmanagedType.LPStr)] string pszMore   // LPCSTR
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function PathAppendA(
    <MarshalAs(UnmanagedType.LPStr)> pszPath As System.Text.StringBuilder,   ' LPSTR in/out
    <MarshalAs(UnmanagedType.LPStr)> pszMore As String   ' LPCSTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' pszPath : LPSTR in/out
' pszMore : LPCSTR
Declare PtrSafe Function PathAppendA Lib "shlwapi" ( _
    ByVal pszPath As String, _
    ByVal pszMore As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathAppendA = ctypes.windll.shlwapi.PathAppendA
PathAppendA.restype = wintypes.BOOL
PathAppendA.argtypes = [
    wintypes.LPSTR,  # pszPath : LPSTR in/out
    wintypes.LPCSTR,  # pszMore : LPCSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
PathAppendA = Fiddle::Function.new(
  lib['PathAppendA'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPSTR in/out
    Fiddle::TYPE_VOIDP,  # pszMore : LPCSTR
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn PathAppendA(
        pszPath: *mut u8,  // LPSTR in/out
        pszMore: *const u8  // LPCSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHLWAPI.dll", CharSet = CharSet.Ansi)]
public static extern bool PathAppendA([MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszPath, [MarshalAs(UnmanagedType.LPStr)] string pszMore);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathAppendA' -Namespace Win32 -PassThru
# $api::PathAppendA(pszPath, pszMore)
#uselib "SHLWAPI.dll"
#func global PathAppendA "PathAppendA" sptr, sptr
; PathAppendA varptr(pszPath), pszMore   ; 戻り値は stat
; pszPath : LPSTR in/out -> "sptr"
; pszMore : LPCSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global PathAppendA "PathAppendA" var, str
; res = PathAppendA(pszPath, pszMore)
; pszPath : LPSTR in/out -> "var"
; pszMore : LPCSTR -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL PathAppendA(LPSTR pszPath, LPCSTR pszMore)
#uselib "SHLWAPI.dll"
#cfunc global PathAppendA "PathAppendA" var, str
; res = PathAppendA(pszPath, pszMore)
; pszPath : LPSTR in/out -> "var"
; pszMore : LPCSTR -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathAppendA = shlwapi.NewProc("PathAppendA")
)

// pszPath (LPSTR in/out), pszMore (LPCSTR)
r1, _, err := procPathAppendA.Call(
	uintptr(pszPath),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pszMore))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function PathAppendA(
  pszPath: PAnsiChar;   // LPSTR in/out
  pszMore: PAnsiChar   // LPCSTR
): BOOL; stdcall;
  external 'SHLWAPI.dll' name 'PathAppendA';
result := DllCall("SHLWAPI\PathAppendA"
    , "Ptr", pszPath   ; LPSTR in/out
    , "AStr", pszMore   ; LPCSTR
    , "Int")   ; return: BOOL
●PathAppendA(pszPath, pszMore) = DLL("SHLWAPI.dll", "bool PathAppendA(char*, char*)")
# 呼び出し: PathAppendA(pszPath, pszMore)
# pszPath : LPSTR in/out -> "char*"
# pszMore : LPCSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "shlwapi" fn PathAppendA(
    pszPath: [*c]u8, // LPSTR in/out
    pszMore: [*c]const u8 // LPCSTR
) callconv(std.os.windows.WINAPI) i32;
proc PathAppendA(
    pszPath: ptr char,  # LPSTR in/out
    pszMore: cstring  # LPCSTR
): int32 {.importc: "PathAppendA", stdcall, dynlib: "SHLWAPI.dll".}
pragma(lib, "shlwapi");
extern(Windows)
int PathAppendA(
    char* pszPath,   // LPSTR in/out
    const(char)* pszMore   // LPCSTR
);
ccall((:PathAppendA, "SHLWAPI.dll"), stdcall, Int32,
      (Ptr{UInt8}, Cstring),
      pszPath, pszMore)
# pszPath : LPSTR in/out -> Ptr{UInt8}
# pszMore : LPCSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t PathAppendA(
    char* pszPath,
    const char* pszMore);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.PathAppendA(pszPath, pszMore)
-- pszPath : LPSTR in/out
-- pszMore : LPCSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const PathAppendA = lib.func('__stdcall', 'PathAppendA', 'int32_t', ['char *', 'str']);
// PathAppendA(pszPath, pszMore)
// pszPath : LPSTR in/out -> 'char *'
// pszMore : LPCSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SHLWAPI.dll", {
  PathAppendA: { parameters: ["buffer", "buffer"], result: "i32" },
});
// lib.symbols.PathAppendA(pszPath, pszMore)
// pszPath : LPSTR in/out -> "buffer"
// pszMore : LPCSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t PathAppendA(
    char* pszPath,
    const char* pszMore);
C, "SHLWAPI.dll");
// $ffi->PathAppendA(pszPath, pszMore);
// pszPath : LPSTR in/out
// pszMore : LPCSTR
// 構造体/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 Shlwapi extends StdCallLibrary {
    Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.ASCII_OPTIONS);
    boolean PathAppendA(
        byte[] pszPath,   // LPSTR in/out
        String pszMore   // LPCSTR
    );
}
@[Link("shlwapi")]
lib LibSHLWAPI
  fun PathAppendA = PathAppendA(
    pszPath : UInt8*,   # LPSTR in/out
    pszMore : UInt8*   # LPCSTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PathAppendANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>);
typedef PathAppendADart = int Function(Pointer<Utf8>, Pointer<Utf8>);
final PathAppendA = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<PathAppendANative, PathAppendADart>('PathAppendA');
// pszPath : LPSTR in/out -> Pointer<Utf8>
// pszMore : LPCSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PathAppendA(
  pszPath: PAnsiChar;   // LPSTR in/out
  pszMore: PAnsiChar   // LPCSTR
): BOOL; stdcall;
  external 'SHLWAPI.dll' name 'PathAppendA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PathAppendA"
  c_PathAppendA :: CString -> CString -> IO CInt
-- pszPath : LPSTR in/out -> CString
-- pszMore : LPCSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pathappenda =
  foreign "PathAppendA"
    (string @-> string @-> returning int32_t)
(* pszPath : LPSTR in/out -> string *)
(* pszMore : LPCSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("PathAppendA" path-append-a :convention :stdcall) :int32
  (psz-path :pointer)   ; LPSTR in/out
  (psz-more :string))   ; LPCSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PathAppendA = Win32::API::More->new('SHLWAPI',
    'BOOL PathAppendA(LPSTR pszPath, LPCSTR pszMore)');
# my $ret = $PathAppendA->Call($pszPath, $pszMore);
# pszPath : LPSTR in/out -> LPSTR
# pszMore : LPCSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い