UrlEscapeW
関数URL中の安全でない文字をパーセントエンコードする。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
HRESULT UrlEscapeW(
LPCWSTR pszUrl,
LPWSTR pszEscaped,
DWORD* pcchEscaped,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszUrl | LPCWSTR | in |
| pszEscaped | LPWSTR | out |
| pcchEscaped | DWORD* | inout |
| dwFlags | DWORD | in |
戻り値の型: HRESULT
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
HRESULT UrlEscapeW(
LPCWSTR pszUrl,
LPWSTR pszEscaped,
DWORD* pcchEscaped,
DWORD dwFlags
);[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int UrlEscapeW(
[MarshalAs(UnmanagedType.LPWStr)] string pszUrl, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszEscaped, // LPWSTR out
ref uint pcchEscaped, // DWORD* in/out
uint dwFlags // DWORD
);<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function UrlEscapeW(
<MarshalAs(UnmanagedType.LPWStr)> pszUrl As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszEscaped As System.Text.StringBuilder, ' LPWSTR out
ByRef pcchEscaped As UInteger, ' DWORD* in/out
dwFlags As UInteger ' DWORD
) As Integer
End Function' pszUrl : LPCWSTR
' pszEscaped : LPWSTR out
' pcchEscaped : DWORD* in/out
' dwFlags : DWORD
Declare PtrSafe Function UrlEscapeW Lib "shlwapi" ( _
ByVal pszUrl As LongPtr, _
ByVal pszEscaped As LongPtr, _
ByRef pcchEscaped As Long, _
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
UrlEscapeW = ctypes.windll.shlwapi.UrlEscapeW
UrlEscapeW.restype = ctypes.c_int
UrlEscapeW.argtypes = [
wintypes.LPCWSTR, # pszUrl : LPCWSTR
wintypes.LPWSTR, # pszEscaped : LPWSTR out
ctypes.POINTER(wintypes.DWORD), # pcchEscaped : DWORD* in/out
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
UrlEscapeW = Fiddle::Function.new(
lib['UrlEscapeW'],
[
Fiddle::TYPE_VOIDP, # pszUrl : LPCWSTR
Fiddle::TYPE_VOIDP, # pszEscaped : LPWSTR out
Fiddle::TYPE_VOIDP, # pcchEscaped : DWORD* 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 UrlEscapeW(
pszUrl: *const u16, // LPCWSTR
pszEscaped: *mut u16, // LPWSTR out
pcchEscaped: *mut u32, // DWORD* 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 UrlEscapeW([MarshalAs(UnmanagedType.LPWStr)] string pszUrl, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszEscaped, ref uint pcchEscaped, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_UrlEscapeW' -Namespace Win32 -PassThru
# $api::UrlEscapeW(pszUrl, pszEscaped, pcchEscaped, dwFlags)#uselib "SHLWAPI.dll"
#func global UrlEscapeW "UrlEscapeW" wptr, wptr, wptr, wptr
; UrlEscapeW pszUrl, varptr(pszEscaped), varptr(pcchEscaped), dwFlags ; 戻り値は stat
; pszUrl : LPCWSTR -> "wptr"
; pszEscaped : LPWSTR out -> "wptr"
; pcchEscaped : DWORD* in/out -> "wptr"
; dwFlags : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHLWAPI.dll" #cfunc global UrlEscapeW "UrlEscapeW" wstr, var, var, int ; res = UrlEscapeW(pszUrl, pszEscaped, pcchEscaped, dwFlags) ; pszUrl : LPCWSTR -> "wstr" ; pszEscaped : LPWSTR out -> "var" ; pcchEscaped : DWORD* in/out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global UrlEscapeW "UrlEscapeW" wstr, sptr, sptr, int ; res = UrlEscapeW(pszUrl, varptr(pszEscaped), varptr(pcchEscaped), dwFlags) ; pszUrl : LPCWSTR -> "wstr" ; pszEscaped : LPWSTR out -> "sptr" ; pcchEscaped : DWORD* in/out -> "sptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT UrlEscapeW(LPCWSTR pszUrl, LPWSTR pszEscaped, DWORD* pcchEscaped, DWORD dwFlags) #uselib "SHLWAPI.dll" #cfunc global UrlEscapeW "UrlEscapeW" wstr, var, var, int ; res = UrlEscapeW(pszUrl, pszEscaped, pcchEscaped, dwFlags) ; pszUrl : LPCWSTR -> "wstr" ; pszEscaped : LPWSTR out -> "var" ; pcchEscaped : DWORD* in/out -> "var" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT UrlEscapeW(LPCWSTR pszUrl, LPWSTR pszEscaped, DWORD* pcchEscaped, DWORD dwFlags) #uselib "SHLWAPI.dll" #cfunc global UrlEscapeW "UrlEscapeW" wstr, intptr, intptr, int ; res = UrlEscapeW(pszUrl, varptr(pszEscaped), varptr(pcchEscaped), dwFlags) ; pszUrl : LPCWSTR -> "wstr" ; pszEscaped : LPWSTR out -> "intptr" ; pcchEscaped : DWORD* in/out -> "intptr" ; dwFlags : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procUrlEscapeW = shlwapi.NewProc("UrlEscapeW")
)
// pszUrl (LPCWSTR), pszEscaped (LPWSTR out), pcchEscaped (DWORD* in/out), dwFlags (DWORD)
r1, _, err := procUrlEscapeW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszUrl))),
uintptr(pszEscaped),
uintptr(pcchEscaped),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction UrlEscapeW(
pszUrl: PWideChar; // LPCWSTR
pszEscaped: PWideChar; // LPWSTR out
pcchEscaped: Pointer; // DWORD* in/out
dwFlags: DWORD // DWORD
): Integer; stdcall;
external 'SHLWAPI.dll' name 'UrlEscapeW';result := DllCall("SHLWAPI\UrlEscapeW"
, "WStr", pszUrl ; LPCWSTR
, "Ptr", pszEscaped ; LPWSTR out
, "Ptr", pcchEscaped ; DWORD* in/out
, "UInt", dwFlags ; DWORD
, "Int") ; return: HRESULT●UrlEscapeW(pszUrl, pszEscaped, pcchEscaped, dwFlags) = DLL("SHLWAPI.dll", "int UrlEscapeW(char*, char*, void*, dword)")
# 呼び出し: UrlEscapeW(pszUrl, pszEscaped, pcchEscaped, dwFlags)
# pszUrl : LPCWSTR -> "char*"
# pszEscaped : LPWSTR out -> "char*"
# pcchEscaped : DWORD* in/out -> "void*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。