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

UrlUnescapeW

関数
URL中のエスケープ表記を元の文字にデコードする。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT UrlUnescapeW(
    LPWSTR pszUrl,
    LPWSTR pszUnescaped,   // optional
    DWORD* pcchUnescaped,   // optional
    DWORD dwFlags
);

パラメーター

名前方向
pszUrlLPWSTRinout
pszUnescapedLPWSTRoutoptional
pcchUnescapedDWORD*inoutoptional
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT UrlUnescapeW(
    LPWSTR pszUrl,
    LPWSTR pszUnescaped,   // optional
    DWORD* pcchUnescaped,   // optional
    DWORD dwFlags
);
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int UrlUnescapeW(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUrl,   // LPWSTR in/out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszUnescaped,   // LPWSTR optional, out
    IntPtr pcchUnescaped,   // DWORD* optional, in/out
    uint dwFlags   // DWORD
);
<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function UrlUnescapeW(
    <MarshalAs(UnmanagedType.LPWStr)> pszUrl As System.Text.StringBuilder,   ' LPWSTR in/out
    <MarshalAs(UnmanagedType.LPWStr)> pszUnescaped As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchUnescaped As IntPtr,   ' DWORD* optional, in/out
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' pszUrl : LPWSTR in/out
' pszUnescaped : LPWSTR optional, out
' pcchUnescaped : DWORD* optional, in/out
' dwFlags : DWORD
Declare PtrSafe Function UrlUnescapeW Lib "shlwapi" ( _
    ByVal pszUrl As LongPtr, _
    ByVal pszUnescaped As LongPtr, _
    ByVal pcchUnescaped As LongPtr, _
    ByVal dwFlags As Long) As Long
' 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

UrlUnescapeW = ctypes.windll.shlwapi.UrlUnescapeW
UrlUnescapeW.restype = ctypes.c_int
UrlUnescapeW.argtypes = [
    wintypes.LPWSTR,  # pszUrl : LPWSTR in/out
    wintypes.LPWSTR,  # pszUnescaped : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchUnescaped : DWORD* optional, in/out
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procUrlUnescapeW = shlwapi.NewProc("UrlUnescapeW")
)

// pszUrl (LPWSTR in/out), pszUnescaped (LPWSTR optional, out), pcchUnescaped (DWORD* optional, in/out), dwFlags (DWORD)
r1, _, err := procUrlUnescapeW.Call(
	uintptr(pszUrl),
	uintptr(pszUnescaped),
	uintptr(pcchUnescaped),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function UrlUnescapeW(
  pszUrl: PWideChar;   // LPWSTR in/out
  pszUnescaped: PWideChar;   // LPWSTR optional, out
  pcchUnescaped: Pointer;   // DWORD* optional, in/out
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'SHLWAPI.dll' name 'UrlUnescapeW';
result := DllCall("SHLWAPI\UrlUnescapeW"
    , "Ptr", pszUrl   ; LPWSTR in/out
    , "Ptr", pszUnescaped   ; LPWSTR optional, out
    , "Ptr", pcchUnescaped   ; DWORD* optional, in/out
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●UrlUnescapeW(pszUrl, pszUnescaped, pcchUnescaped, dwFlags) = DLL("SHLWAPI.dll", "int UrlUnescapeW(char*, char*, void*, dword)")
# 呼び出し: UrlUnescapeW(pszUrl, pszUnescaped, pcchUnescaped, dwFlags)
# pszUrl : LPWSTR in/out -> "char*"
# pszUnescaped : LPWSTR optional, out -> "char*"
# pcchUnescaped : DWORD* optional, in/out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。