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

PathCreateFromUrlAlloc

関数
URLをファイルパスに変換し結果バッファを自動確保して返す。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// SHLWAPI.dll
#include <windows.h>

HRESULT PathCreateFromUrlAlloc(
    LPCWSTR pszIn,
    LPWSTR* ppszOut,
    DWORD dwFlags
);

パラメーター

名前方向
pszInLPCWSTRin
ppszOutLPWSTR*out
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

// SHLWAPI.dll
#include <windows.h>

HRESULT PathCreateFromUrlAlloc(
    LPCWSTR pszIn,
    LPWSTR* ppszOut,
    DWORD dwFlags
);
[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern int PathCreateFromUrlAlloc(
    [MarshalAs(UnmanagedType.LPWStr)] string pszIn,   // LPCWSTR
    IntPtr ppszOut,   // LPWSTR* out
    uint dwFlags   // DWORD
);
<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function PathCreateFromUrlAlloc(
    <MarshalAs(UnmanagedType.LPWStr)> pszIn As String,   ' LPCWSTR
    ppszOut As IntPtr,   ' LPWSTR* out
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' pszIn : LPCWSTR
' ppszOut : LPWSTR* out
' dwFlags : DWORD
Declare PtrSafe Function PathCreateFromUrlAlloc Lib "shlwapi" ( _
    ByVal pszIn As LongPtr, _
    ByVal ppszOut 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

PathCreateFromUrlAlloc = ctypes.windll.shlwapi.PathCreateFromUrlAlloc
PathCreateFromUrlAlloc.restype = ctypes.c_int
PathCreateFromUrlAlloc.argtypes = [
    wintypes.LPCWSTR,  # pszIn : LPCWSTR
    ctypes.c_void_p,  # ppszOut : LPWSTR* out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
PathCreateFromUrlAlloc = Fiddle::Function.new(
  lib['PathCreateFromUrlAlloc'],
  [
    Fiddle::TYPE_VOIDP,  # pszIn : LPCWSTR
    Fiddle::TYPE_VOIDP,  # ppszOut : LPWSTR* out
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn PathCreateFromUrlAlloc(
        pszIn: *const u16,  // LPCWSTR
        ppszOut: *mut *mut u16,  // LPWSTR* out
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll")]
public static extern int PathCreateFromUrlAlloc([MarshalAs(UnmanagedType.LPWStr)] string pszIn, IntPtr ppszOut, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_PathCreateFromUrlAlloc' -Namespace Win32 -PassThru
# $api::PathCreateFromUrlAlloc(pszIn, ppszOut, dwFlags)
#uselib "SHLWAPI.dll"
#func global PathCreateFromUrlAlloc "PathCreateFromUrlAlloc" sptr, sptr, sptr
; PathCreateFromUrlAlloc pszIn, varptr(ppszOut), dwFlags   ; 戻り値は stat
; pszIn : LPCWSTR -> "sptr"
; ppszOut : LPWSTR* out -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHLWAPI.dll"
#cfunc global PathCreateFromUrlAlloc "PathCreateFromUrlAlloc" wstr, var, int
; res = PathCreateFromUrlAlloc(pszIn, ppszOut, dwFlags)
; pszIn : LPCWSTR -> "wstr"
; ppszOut : LPWSTR* out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT PathCreateFromUrlAlloc(LPCWSTR pszIn, LPWSTR* ppszOut, DWORD dwFlags)
#uselib "SHLWAPI.dll"
#cfunc global PathCreateFromUrlAlloc "PathCreateFromUrlAlloc" wstr, var, int
; res = PathCreateFromUrlAlloc(pszIn, ppszOut, dwFlags)
; pszIn : LPCWSTR -> "wstr"
; ppszOut : LPWSTR* out -> "var"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procPathCreateFromUrlAlloc = shlwapi.NewProc("PathCreateFromUrlAlloc")
)

// pszIn (LPCWSTR), ppszOut (LPWSTR* out), dwFlags (DWORD)
r1, _, err := procPathCreateFromUrlAlloc.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszIn))),
	uintptr(ppszOut),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function PathCreateFromUrlAlloc(
  pszIn: PWideChar;   // LPCWSTR
  ppszOut: PPWideChar;   // LPWSTR* out
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'PathCreateFromUrlAlloc';
result := DllCall("SHLWAPI\PathCreateFromUrlAlloc"
    , "WStr", pszIn   ; LPCWSTR
    , "Ptr", ppszOut   ; LPWSTR* out
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●PathCreateFromUrlAlloc(pszIn, ppszOut, dwFlags) = DLL("SHLWAPI.dll", "int PathCreateFromUrlAlloc(char*, void*, dword)")
# 呼び出し: PathCreateFromUrlAlloc(pszIn, ppszOut, dwFlags)
# pszIn : LPCWSTR -> "char*"
# ppszOut : LPWSTR* out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。