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

PathCombineW

関数
ディレクトリパスとファイル名を連結し、正規化された1つのパスを生成する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

LPWSTR PathCombineW(
    LPWSTR pszDest,
    LPCWSTR pszDir,   // optional
    LPCWSTR pszFile   // optional
);

パラメーター

名前方向
pszDestLPWSTRout
pszDirLPCWSTRinoptional
pszFileLPCWSTRinoptional

戻り値の型: LPWSTR

各言語での呼び出し定義

// SHLWAPI.dll  (Unicode / -W)
#include <windows.h>

LPWSTR PathCombineW(
    LPWSTR pszDest,
    LPCWSTR pszDir,   // optional
    LPCWSTR pszFile   // optional
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr PathCombineW(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszDest,   // LPWSTR out
    [MarshalAs(UnmanagedType.LPWStr)] string pszDir,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszFile   // LPCWSTR optional
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function PathCombineW(
    <MarshalAs(UnmanagedType.LPWStr)> pszDest As System.Text.StringBuilder,   ' LPWSTR out
    <MarshalAs(UnmanagedType.LPWStr)> pszDir As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszFile As String   ' LPCWSTR optional
) As IntPtr
End Function
' pszDest : LPWSTR out
' pszDir : LPCWSTR optional
' pszFile : LPCWSTR optional
Declare PtrSafe Function PathCombineW Lib "shlwapi" ( _
    ByVal pszDest As LongPtr, _
    ByVal pszDir As LongPtr, _
    ByVal pszFile As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathCombineW = ctypes.windll.shlwapi.PathCombineW
PathCombineW.restype = wintypes.LPWSTR
PathCombineW.argtypes = [
    wintypes.LPWSTR,  # pszDest : LPWSTR out
    wintypes.LPCWSTR,  # pszDir : LPCWSTR optional
    wintypes.LPCWSTR,  # pszFile : LPCWSTR optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathCombineW = shlwapi.NewProc("PathCombineW")
)

// pszDest (LPWSTR out), pszDir (LPCWSTR optional), pszFile (LPCWSTR optional)
r1, _, err := procPathCombineW.Call(
	uintptr(pszDest),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszDir))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszFile))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPWSTR
function PathCombineW(
  pszDest: PWideChar;   // LPWSTR out
  pszDir: PWideChar;   // LPCWSTR optional
  pszFile: PWideChar   // LPCWSTR optional
): PWideChar; stdcall;
  external 'SHLWAPI.dll' name 'PathCombineW';
result := DllCall("SHLWAPI\PathCombineW"
    , "Ptr", pszDest   ; LPWSTR out
    , "WStr", pszDir   ; LPCWSTR optional
    , "WStr", pszFile   ; LPCWSTR optional
    , "Ptr")   ; return: LPWSTR
●PathCombineW(pszDest, pszDir, pszFile) = DLL("SHLWAPI.dll", "char* PathCombineW(char*, char*, char*)")
# 呼び出し: PathCombineW(pszDest, pszDir, pszFile)
# pszDest : LPWSTR out -> "char*"
# pszDir : LPCWSTR optional -> "char*"
# pszFile : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。