UrlUnescapeW
関数シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
HRESULT UrlUnescapeW(
LPWSTR pszUrl,
LPWSTR pszUnescaped, // optional
DWORD* pcchUnescaped, // optional
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszUrl | LPWSTR | inout | URL を表す null 終端文字列へのポインター。dwFlags に URL_UNESCAPE_INPLACE が設定されている場合、変換後の文字列はこのパラメーターを通じて返されます。 |
| pszUnescaped | LPWSTR | outoptional | pszURL のアンエスケープ済みバージョンを格納する null 終端文字列を受け取るバッファーへのポインター。dwFlags に URL_UNESCAPE_INPLACE が設定されている場合、このパラメーターは無視されます。 |
| pcchUnescaped | DWORD* | inoutoptional | pszUnescaped が指すバッファー内の文字数。呼び出し時には、pcchUnescaped が指す値にバッファーのサイズを設定します。関数が成功コードを返し、かつ URL_UNESCAPE_INPLACE フラグが設定されていない場合、pcchUnescaped が指す値には、終端の NULL 文字を含まない、そのバッファーに書き込まれた文字数が設定されます。E_POINTER エラーコードが返された場合、バッファーが小さすぎたことを意味し、pcchUnescaped が指す値にはバッファーが格納できる必要のある文字数が設定されます。その他のエラーが返された場合、pcchUnescaped が指す値は未定義です。 |
| dwFlags | DWORD | in | どの文字をアンエスケープするかを制御するフラグ。次のフラグの組み合わせを指定できます。 URL_DONT_UNESCAPE_EXTRA_INFOまたは ? 文字、およびそれらに続く文字列中の文字を変換しません。URL_UNESCAPE_AS_UTF8Windows 8 で導入されました。URL_ESCAPE_AS_UTF8 フラグを使用してエンコードされた URL をデコードします。 URL_UNESCAPE_INPLACEpszUnescaped ではなく pszURL を使用して変換後の文字列を返します。 - dwFlags.URL_DONT_UNESCAPE_EXTRA_INFOまたは ? 文字、およびそれらに続く文字列中の文字を変換しません。- dwFlags.URL_UNESCAPE_AS_UTF8Windows 8 で導入されました。URL_ESCAPE_AS_UTF8 フラグを使用してエンコードされた URL をデコードします。 - dwFlags.URL_UNESCAPE_INPLACEpszUnescaped ではなく pszURL を使用して変換後の文字列を返します。 |
戻り値の型: HRESULT
公式ドキュメント
エスケープシーケンスを通常の文字に戻します。(Unicode)
戻り値
型: HRESULT
成功した場合は S_OK を返します。URL_UNESCAPE_INPLACE フラグが設定されていない場合、pcchUnescaped が指す値には、pszUnescaped が指す出力バッファー内の文字数が設定されます。URL_UNESCAPE_INPLACE フラグが設定されておらず、かつ出力バッファーが小さすぎる場合は E_POINTER を返します。その場合、pcchUnescaped パラメーターには必要なバッファーサイズが設定されます。それ以外の場合は、標準のエラー値を返します。
解説(Remarks)
エスケープシーケンスは "%xy" の形式を持ちます。
入力文字列は INTERNET_MAX_URL_LENGTH を超えることはできません。
shlwapi.h ヘッダーは UrlUnescape をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング中立なエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーを引き起こす可能性があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global UrlUnescapeW "UrlUnescapeW" sptr, sptr, sptr, int ; res = UrlUnescapeW(varptr(pszUrl), varptr(pszUnescaped), varptr(pcchUnescaped), dwFlags) ; pszUrl : LPWSTR in/out -> "sptr" ; pszUnescaped : LPWSTR optional, out -> "sptr" ; pcchUnescaped : DWORD* optional, in/out -> "sptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; HRESULT UrlUnescapeW(LPWSTR pszUrl, LPWSTR pszUnescaped, DWORD* pcchUnescaped, DWORD dwFlags) #uselib "SHLWAPI.dll" #cfunc global UrlUnescapeW "UrlUnescapeW" intptr, intptr, intptr, int ; res = UrlUnescapeW(varptr(pszUrl), varptr(pszUnescaped), varptr(pcchUnescaped), dwFlags) ; pszUrl : LPWSTR in/out -> "intptr" ; pszUnescaped : LPWSTR optional, out -> "intptr" ; pcchUnescaped : DWORD* optional, in/out -> "intptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HRESULTfunction 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 版の利用を推奨。const std = @import("std");
extern "shlwapi" fn UrlUnescapeW(
pszUrl: [*c]u16, // LPWSTR in/out
pszUnescaped: [*c]u16, // LPWSTR optional, out
pcchUnescaped: [*c]u32, // DWORD* optional, in/out
dwFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc UrlUnescapeW(
pszUrl: ptr uint16, # LPWSTR in/out
pszUnescaped: ptr uint16, # LPWSTR optional, out
pcchUnescaped: ptr uint32, # DWORD* optional, in/out
dwFlags: uint32 # DWORD
): int32 {.importc: "UrlUnescapeW", stdcall, dynlib: "SHLWAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "shlwapi");
extern(Windows)
int UrlUnescapeW(
wchar* pszUrl, // LPWSTR in/out
wchar* pszUnescaped, // LPWSTR optional, out
uint* pcchUnescaped, // DWORD* optional, in/out
uint dwFlags // DWORD
);ccall((:UrlUnescapeW, "SHLWAPI.dll"), stdcall, Int32,
(Ptr{UInt16}, Ptr{UInt16}, Ptr{UInt32}, UInt32),
pszUrl, pszUnescaped, pcchUnescaped, dwFlags)
# pszUrl : LPWSTR in/out -> Ptr{UInt16}
# pszUnescaped : LPWSTR optional, out -> Ptr{UInt16}
# pcchUnescaped : DWORD* optional, in/out -> Ptr{UInt32}
# dwFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t UrlUnescapeW(
uint16_t* pszUrl,
uint16_t* pszUnescaped,
uint32_t* pcchUnescaped,
uint32_t dwFlags);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.UrlUnescapeW(pszUrl, pszUnescaped, pcchUnescaped, dwFlags)
-- pszUrl : LPWSTR in/out
-- pszUnescaped : LPWSTR optional, out
-- pcchUnescaped : DWORD* optional, in/out
-- dwFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const UrlUnescapeW = lib.func('__stdcall', 'UrlUnescapeW', 'int32_t', ['uint16_t *', 'uint16_t *', 'uint32_t *', 'uint32_t']);
// UrlUnescapeW(pszUrl, pszUnescaped, pcchUnescaped, dwFlags)
// pszUrl : LPWSTR in/out -> 'uint16_t *'
// pszUnescaped : LPWSTR optional, out -> 'uint16_t *'
// pcchUnescaped : DWORD* optional, in/out -> 'uint32_t *'
// dwFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
UrlUnescapeW: { parameters: ["buffer", "buffer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.UrlUnescapeW(pszUrl, pszUnescaped, pcchUnescaped, dwFlags)
// pszUrl : LPWSTR in/out -> "buffer"
// pszUnescaped : LPWSTR optional, out -> "buffer"
// pcchUnescaped : DWORD* optional, in/out -> "pointer"
// dwFlags : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t UrlUnescapeW(
uint16_t* pszUrl,
uint16_t* pszUnescaped,
uint32_t* pcchUnescaped,
uint32_t dwFlags);
C, "SHLWAPI.dll");
// $ffi->UrlUnescapeW(pszUrl, pszUnescaped, pcchUnescaped, dwFlags);
// pszUrl : LPWSTR in/out
// pszUnescaped : LPWSTR optional, out
// pcchUnescaped : DWORD* optional, in/out
// dwFlags : DWORD
// 構造体/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 Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.UNICODE_OPTIONS);
int UrlUnescapeW(
char[] pszUrl, // LPWSTR in/out
char[] pszUnescaped, // LPWSTR optional, out
IntByReference pcchUnescaped, // DWORD* optional, in/out
int dwFlags // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("shlwapi")]
lib LibSHLWAPI
fun UrlUnescapeW = UrlUnescapeW(
pszUrl : UInt16*, # LPWSTR in/out
pszUnescaped : UInt16*, # LPWSTR optional, out
pcchUnescaped : UInt32*, # DWORD* optional, in/out
dwFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef UrlUnescapeWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Uint32);
typedef UrlUnescapeWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, int);
final UrlUnescapeW = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<UrlUnescapeWNative, UrlUnescapeWDart>('UrlUnescapeW');
// pszUrl : LPWSTR in/out -> Pointer<Utf16>
// pszUnescaped : LPWSTR optional, out -> Pointer<Utf16>
// pcchUnescaped : DWORD* optional, in/out -> Pointer<Uint32>
// dwFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "UrlUnescapeW"
c_UrlUnescapeW :: CWString -> CWString -> Ptr Word32 -> Word32 -> IO Int32
-- pszUrl : LPWSTR in/out -> CWString
-- pszUnescaped : LPWSTR optional, out -> CWString
-- pcchUnescaped : DWORD* optional, in/out -> Ptr Word32
-- dwFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let urlunescapew =
foreign "UrlUnescapeW"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> uint32_t @-> returning int32_t)
(* pszUrl : LPWSTR in/out -> (ptr uint16_t) *)
(* pszUnescaped : LPWSTR optional, out -> (ptr uint16_t) *)
(* pcchUnescaped : DWORD* optional, in/out -> (ptr uint32_t) *)
(* dwFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("UrlUnescapeW" url-unescape-w :convention :stdcall) :int32
(psz-url :pointer) ; LPWSTR in/out
(psz-unescaped :pointer) ; LPWSTR optional, out
(pcch-unescaped :pointer) ; DWORD* optional, in/out
(dw-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $UrlUnescapeW = Win32::API::More->new('SHLWAPI',
'int UrlUnescapeW(LPWSTR pszUrl, LPWSTR pszUnescaped, LPVOID pcchUnescaped, DWORD dwFlags)');
# my $ret = $UrlUnescapeW->Call($pszUrl, $pszUnescaped, $pcchUnescaped, $dwFlags);
# pszUrl : LPWSTR in/out -> LPWSTR
# pszUnescaped : LPWSTR optional, out -> LPWSTR
# pcchUnescaped : DWORD* optional, in/out -> LPVOID
# dwFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f UrlUnescapeA (ANSI版) — URL中のエスケープ表記を元の文字にデコードする。