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

PathCombineA

関数
ディレクトリとファイル名を結合して完全なパスを作る。
DLLSHLWAPI.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

LPSTR PathCombineA(
    LPSTR pszDest,
    LPCSTR pszDir,   // optional
    LPCSTR pszFile   // optional
);

パラメーター

名前方向
pszDestLPSTRout
pszDirLPCSTRinoptional
pszFileLPCSTRinoptional

戻り値の型: LPSTR

各言語での呼び出し定義

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

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

PathCombineA = ctypes.windll.shlwapi.PathCombineA
PathCombineA.restype = wintypes.LPSTR
PathCombineA.argtypes = [
    wintypes.LPSTR,  # pszDest : LPSTR out
    wintypes.LPCSTR,  # pszDir : LPCSTR optional
    wintypes.LPCSTR,  # pszFile : LPCSTR optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathCombineA = shlwapi.NewProc("PathCombineA")
)

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