PathAllocCombine
関数2つのパスを連結し結果バッファを自動確保する。
シグネチャ
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathAllocCombine(
LPCWSTR pszPathIn, // optional
LPCWSTR pszMore, // optional
PATHCCH_OPTIONS dwFlags,
LPWSTR* ppszPathOut
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| pszPathIn | LPCWSTR | inoptional | 1 つ目のパス文字列へのポインター。 | ||||||||||||||||
| pszMore | LPCWSTR | inoptional | 2 つ目のパス文字列へのポインター。このパスが 1 つのバックスラッシュで始まる場合、pszPathIn が指すパスのルート部分のみと結合されます。このパスが完全修飾されている場合は、もう一方のパスと結合されることなく、そのまま出力バッファーにコピーされます。 | ||||||||||||||||
| dwFlags | PATHCCH_OPTIONS | in | 次のフラグのうち 1 つ以上を指定します。
| ||||||||||||||||
| ppszPathOut | LPWSTR* | out | バッファーへのポインターのアドレス。この関数が正常に終了すると、結合されたパス文字列を受け取ります。このリソースが不要になったときに LocalFree 関数を呼び出して解放するのは、呼び出し元の責任です。この値を NULL にすることはできません。 |
戻り値の型: HRESULT
公式ドキュメント
2 つのパス断片を 1 つのパスに連結します。
戻り値
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。
解説(Remarks)
pszPathIn または pszMore のいずれかを NULL にすることはできますが、両方を同時に NULL にすることはできません。
この関数は次の代替パス形式をサポートします。
- \\?\
- \\?\\UNC\
- \\?\Volume{guid}\
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// api-ms-win-core-path-l1-1-0.dll
#include <windows.h>
HRESULT PathAllocCombine(
LPCWSTR pszPathIn, // optional
LPCWSTR pszMore, // optional
PATHCCH_OPTIONS dwFlags,
LPWSTR* ppszPathOut
);[DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling = true)]
static extern int PathAllocCombine(
[MarshalAs(UnmanagedType.LPWStr)] string pszPathIn, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pszMore, // LPCWSTR optional
uint dwFlags, // PATHCCH_OPTIONS
IntPtr ppszPathOut // LPWSTR* out
);<DllImport("api-ms-win-core-path-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function PathAllocCombine(
<MarshalAs(UnmanagedType.LPWStr)> pszPathIn As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pszMore As String, ' LPCWSTR optional
dwFlags As UInteger, ' PATHCCH_OPTIONS
ppszPathOut As IntPtr ' LPWSTR* out
) As Integer
End Function' pszPathIn : LPCWSTR optional
' pszMore : LPCWSTR optional
' dwFlags : PATHCCH_OPTIONS
' ppszPathOut : LPWSTR* out
Declare PtrSafe Function PathAllocCombine Lib "api-ms-win-core-path-l1-1-0" ( _
ByVal pszPathIn As LongPtr, _
ByVal pszMore As LongPtr, _
ByVal dwFlags As Long, _
ByVal ppszPathOut As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PathAllocCombine = ctypes.windll.LoadLibrary("api-ms-win-core-path-l1-1-0.dll").PathAllocCombine
PathAllocCombine.restype = ctypes.c_int
PathAllocCombine.argtypes = [
wintypes.LPCWSTR, # pszPathIn : LPCWSTR optional
wintypes.LPCWSTR, # pszMore : LPCWSTR optional
wintypes.DWORD, # dwFlags : PATHCCH_OPTIONS
ctypes.c_void_p, # ppszPathOut : LPWSTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-path-l1-1-0.dll')
PathAllocCombine = Fiddle::Function.new(
lib['PathAllocCombine'],
[
Fiddle::TYPE_VOIDP, # pszPathIn : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pszMore : LPCWSTR optional
-Fiddle::TYPE_INT, # dwFlags : PATHCCH_OPTIONS
Fiddle::TYPE_VOIDP, # ppszPathOut : LPWSTR* out
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-path-l1-1-0")]
extern "system" {
fn PathAllocCombine(
pszPathIn: *const u16, // LPCWSTR optional
pszMore: *const u16, // LPCWSTR optional
dwFlags: u32, // PATHCCH_OPTIONS
ppszPathOut: *mut *mut u16 // LPWSTR* out
) -> 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 PathAllocCombine([MarshalAs(UnmanagedType.LPWStr)] string pszPathIn, [MarshalAs(UnmanagedType.LPWStr)] string pszMore, uint dwFlags, IntPtr ppszPathOut);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-path-l1-1-0_PathAllocCombine' -Namespace Win32 -PassThru
# $api::PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut)#uselib "api-ms-win-core-path-l1-1-0.dll"
#func global PathAllocCombine "PathAllocCombine" sptr, sptr, sptr, sptr
; PathAllocCombine pszPathIn, pszMore, dwFlags, varptr(ppszPathOut) ; 戻り値は stat
; pszPathIn : LPCWSTR optional -> "sptr"
; pszMore : LPCWSTR optional -> "sptr"
; dwFlags : PATHCCH_OPTIONS -> "sptr"
; ppszPathOut : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathAllocCombine "PathAllocCombine" wstr, wstr, int, var ; res = PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut) ; pszPathIn : LPCWSTR optional -> "wstr" ; pszMore : LPCWSTR optional -> "wstr" ; dwFlags : PATHCCH_OPTIONS -> "int" ; ppszPathOut : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathAllocCombine "PathAllocCombine" wstr, wstr, int, sptr ; res = PathAllocCombine(pszPathIn, pszMore, dwFlags, varptr(ppszPathOut)) ; pszPathIn : LPCWSTR optional -> "wstr" ; pszMore : LPCWSTR optional -> "wstr" ; dwFlags : PATHCCH_OPTIONS -> "int" ; ppszPathOut : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT PathAllocCombine(LPCWSTR pszPathIn, LPCWSTR pszMore, PATHCCH_OPTIONS dwFlags, LPWSTR* ppszPathOut) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathAllocCombine "PathAllocCombine" wstr, wstr, int, var ; res = PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut) ; pszPathIn : LPCWSTR optional -> "wstr" ; pszMore : LPCWSTR optional -> "wstr" ; dwFlags : PATHCCH_OPTIONS -> "int" ; ppszPathOut : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT PathAllocCombine(LPCWSTR pszPathIn, LPCWSTR pszMore, PATHCCH_OPTIONS dwFlags, LPWSTR* ppszPathOut) #uselib "api-ms-win-core-path-l1-1-0.dll" #cfunc global PathAllocCombine "PathAllocCombine" wstr, wstr, int, intptr ; res = PathAllocCombine(pszPathIn, pszMore, dwFlags, varptr(ppszPathOut)) ; pszPathIn : LPCWSTR optional -> "wstr" ; pszMore : LPCWSTR optional -> "wstr" ; dwFlags : PATHCCH_OPTIONS -> "int" ; ppszPathOut : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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")
procPathAllocCombine = api_ms_win_core_path_l1_1_0.NewProc("PathAllocCombine")
)
// pszPathIn (LPCWSTR optional), pszMore (LPCWSTR optional), dwFlags (PATHCCH_OPTIONS), ppszPathOut (LPWSTR* out)
r1, _, err := procPathAllocCombine.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPathIn))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszMore))),
uintptr(dwFlags),
uintptr(ppszPathOut),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction PathAllocCombine(
pszPathIn: PWideChar; // LPCWSTR optional
pszMore: PWideChar; // LPCWSTR optional
dwFlags: DWORD; // PATHCCH_OPTIONS
ppszPathOut: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'api-ms-win-core-path-l1-1-0.dll' name 'PathAllocCombine';result := DllCall("api-ms-win-core-path-l1-1-0\PathAllocCombine"
, "WStr", pszPathIn ; LPCWSTR optional
, "WStr", pszMore ; LPCWSTR optional
, "UInt", dwFlags ; PATHCCH_OPTIONS
, "Ptr", ppszPathOut ; LPWSTR* out
, "Int") ; return: HRESULT●PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut) = DLL("api-ms-win-core-path-l1-1-0.dll", "int PathAllocCombine(char*, char*, dword, void*)")
# 呼び出し: PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut)
# pszPathIn : LPCWSTR optional -> "char*"
# pszMore : LPCWSTR optional -> "char*"
# dwFlags : PATHCCH_OPTIONS -> "dword"
# ppszPathOut : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-core-path-l1-1-0" fn PathAllocCombine(
pszPathIn: [*c]const u16, // LPCWSTR optional
pszMore: [*c]const u16, // LPCWSTR optional
dwFlags: u32, // PATHCCH_OPTIONS
ppszPathOut: [*c][*c]u16 // LPWSTR* out
) callconv(std.os.windows.WINAPI) i32;proc PathAllocCombine(
pszPathIn: WideCString, # LPCWSTR optional
pszMore: WideCString, # LPCWSTR optional
dwFlags: uint32, # PATHCCH_OPTIONS
ppszPathOut: ptr WideCString # LPWSTR* out
): int32 {.importc: "PathAllocCombine", stdcall, dynlib: "api-ms-win-core-path-l1-1-0.dll".}pragma(lib, "api-ms-win-core-path-l1-1-0");
extern(Windows)
int PathAllocCombine(
const(wchar)* pszPathIn, // LPCWSTR optional
const(wchar)* pszMore, // LPCWSTR optional
uint dwFlags, // PATHCCH_OPTIONS
wchar** ppszPathOut // LPWSTR* out
);ccall((:PathAllocCombine, "api-ms-win-core-path-l1-1-0.dll"), stdcall, Int32,
(Cwstring, Cwstring, UInt32, Ptr{Ptr{UInt16}}),
pszPathIn, pszMore, dwFlags, ppszPathOut)
# pszPathIn : LPCWSTR optional -> Cwstring
# pszMore : LPCWSTR optional -> Cwstring
# dwFlags : PATHCCH_OPTIONS -> UInt32
# ppszPathOut : LPWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PathAllocCombine(
const uint16_t* pszPathIn,
const uint16_t* pszMore,
uint32_t dwFlags,
uint16_t** ppszPathOut);
]]
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.PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut)
-- pszPathIn : LPCWSTR optional
-- pszMore : LPCWSTR optional
-- dwFlags : PATHCCH_OPTIONS
-- ppszPathOut : LPWSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-path-l1-1-0.dll');
const PathAllocCombine = lib.func('__stdcall', 'PathAllocCombine', 'int32_t', ['str16', 'str16', 'uint32_t', 'void *']);
// PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut)
// pszPathIn : LPCWSTR optional -> 'str16'
// pszMore : LPCWSTR optional -> 'str16'
// dwFlags : PATHCCH_OPTIONS -> 'uint32_t'
// ppszPathOut : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-path-l1-1-0.dll", {
PathAllocCombine: { parameters: ["buffer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut)
// pszPathIn : LPCWSTR optional -> "buffer"
// pszMore : LPCWSTR optional -> "buffer"
// dwFlags : PATHCCH_OPTIONS -> "u32"
// ppszPathOut : LPWSTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PathAllocCombine(
const uint16_t* pszPathIn,
const uint16_t* pszMore,
uint32_t dwFlags,
uint16_t** ppszPathOut);
C, "api-ms-win-core-path-l1-1-0.dll");
// $ffi->PathAllocCombine(pszPathIn, pszMore, dwFlags, ppszPathOut);
// pszPathIn : LPCWSTR optional
// pszMore : LPCWSTR optional
// dwFlags : PATHCCH_OPTIONS
// ppszPathOut : LPWSTR* out
// 構造体/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 PathAllocCombine(
WString pszPathIn, // LPCWSTR optional
WString pszMore, // LPCWSTR optional
int dwFlags, // PATHCCH_OPTIONS
PointerByReference ppszPathOut // LPWSTR* out
);
}@[Link("api-ms-win-core-path-l1-1-0")]
lib Libapi-ms-win-core-path-l1-1-0
fun PathAllocCombine = PathAllocCombine(
pszPathIn : UInt16*, # LPCWSTR optional
pszMore : UInt16*, # LPCWSTR optional
dwFlags : UInt32, # PATHCCH_OPTIONS
ppszPathOut : UInt16** # LPWSTR* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PathAllocCombineNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Pointer<Utf16>>);
typedef PathAllocCombineDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Pointer<Utf16>>);
final PathAllocCombine = DynamicLibrary.open('api-ms-win-core-path-l1-1-0.dll')
.lookupFunction<PathAllocCombineNative, PathAllocCombineDart>('PathAllocCombine');
// pszPathIn : LPCWSTR optional -> Pointer<Utf16>
// pszMore : LPCWSTR optional -> Pointer<Utf16>
// dwFlags : PATHCCH_OPTIONS -> Uint32
// ppszPathOut : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PathAllocCombine(
pszPathIn: PWideChar; // LPCWSTR optional
pszMore: PWideChar; // LPCWSTR optional
dwFlags: DWORD; // PATHCCH_OPTIONS
ppszPathOut: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'api-ms-win-core-path-l1-1-0.dll' name 'PathAllocCombine';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PathAllocCombine"
c_PathAllocCombine :: CWString -> CWString -> Word32 -> Ptr CWString -> IO Int32
-- pszPathIn : LPCWSTR optional -> CWString
-- pszMore : LPCWSTR optional -> CWString
-- dwFlags : PATHCCH_OPTIONS -> Word32
-- ppszPathOut : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pathalloccombine =
foreign "PathAllocCombine"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* pszPathIn : LPCWSTR optional -> (ptr uint16_t) *)
(* pszMore : LPCWSTR optional -> (ptr uint16_t) *)
(* dwFlags : PATHCCH_OPTIONS -> uint32_t *)
(* ppszPathOut : LPWSTR* out -> (ptr (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 ("PathAllocCombine" path-alloc-combine :convention :stdcall) :int32
(psz-path-in (:string :encoding :utf-16le)) ; LPCWSTR optional
(psz-more (:string :encoding :utf-16le)) ; LPCWSTR optional
(dw-flags :uint32) ; PATHCCH_OPTIONS
(ppsz-path-out :pointer)) ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PathAllocCombine = Win32::API::More->new('api-ms-win-core-path-l1-1-0',
'int PathAllocCombine(LPCWSTR pszPathIn, LPCWSTR pszMore, DWORD dwFlags, LPVOID ppszPathOut)');
# my $ret = $PathAllocCombine->Call($pszPathIn, $pszMore, $dwFlags, $ppszPathOut);
# pszPathIn : LPCWSTR optional -> LPCWSTR
# pszMore : LPCWSTR optional -> LPCWSTR
# dwFlags : PATHCCH_OPTIONS -> DWORD
# ppszPathOut : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f PathCchCombine — 2つのパス文字列を安全に連結して正規化する。
- f PathCchCombineEx — オプション指定で2つのパスを安全に連結し正規化する。
使用する型