Win32 API 日本語リファレンス
ホームDevices.WebServicesOnDevices › WSDUriEncode

WSDUriEncode

関数
文字列をWSDで使用するURI形式にエンコードする。
DLLwsdapi.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WSDUriEncode(
    LPCWSTR source,
    DWORD cchSource,
    LPWSTR* destOut,
    DWORD* cchDestOut   // optional
);

パラメーター

名前方向説明
sourceLPCWSTRinURIエンコード対象の入力文字列。
cchSourceDWORDin入力文字列の文字数。0なら自動でNULL終端まで計算する。
destOutLPWSTR*outエンコード結果文字列を受け取る出力ポインタ。
cchDestOutDWORD*outoptional出力文字列の文字数を受け取る出力先。NULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT WSDUriEncode(
    LPCWSTR source,
    DWORD cchSource,
    LPWSTR* destOut,
    DWORD* cchDestOut   // optional
);
[DllImport("wsdapi.dll", ExactSpelling = true)]
static extern int WSDUriEncode(
    [MarshalAs(UnmanagedType.LPWStr)] string source,   // LPCWSTR
    uint cchSource,   // DWORD
    IntPtr destOut,   // LPWSTR* out
    IntPtr cchDestOut   // DWORD* optional, out
);
<DllImport("wsdapi.dll", ExactSpelling:=True)>
Public Shared Function WSDUriEncode(
    <MarshalAs(UnmanagedType.LPWStr)> source As String,   ' LPCWSTR
    cchSource As UInteger,   ' DWORD
    destOut As IntPtr,   ' LPWSTR* out
    cchDestOut As IntPtr   ' DWORD* optional, out
) As Integer
End Function
' source : LPCWSTR
' cchSource : DWORD
' destOut : LPWSTR* out
' cchDestOut : DWORD* optional, out
Declare PtrSafe Function WSDUriEncode Lib "wsdapi" ( _
    ByVal source As LongPtr, _
    ByVal cchSource As Long, _
    ByVal destOut As LongPtr, _
    ByVal cchDestOut As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WSDUriEncode = ctypes.windll.wsdapi.WSDUriEncode
WSDUriEncode.restype = ctypes.c_int
WSDUriEncode.argtypes = [
    wintypes.LPCWSTR,  # source : LPCWSTR
    wintypes.DWORD,  # cchSource : DWORD
    ctypes.c_void_p,  # destOut : LPWSTR* out
    ctypes.POINTER(wintypes.DWORD),  # cchDestOut : DWORD* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	wsdapi = windows.NewLazySystemDLL("wsdapi.dll")
	procWSDUriEncode = wsdapi.NewProc("WSDUriEncode")
)

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

extern "wsdapi" fn WSDUriEncode(
    source: [*c]const u16, // LPCWSTR
    cchSource: u32, // DWORD
    destOut: [*c][*c]u16, // LPWSTR* out
    cchDestOut: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc WSDUriEncode(
    source: WideCString,  # LPCWSTR
    cchSource: uint32,  # DWORD
    destOut: ptr WideCString,  # LPWSTR* out
    cchDestOut: ptr uint32  # DWORD* optional, out
): int32 {.importc: "WSDUriEncode", stdcall, dynlib: "wsdapi.dll".}
pragma(lib, "wsdapi");
extern(Windows)
int WSDUriEncode(
    const(wchar)* source,   // LPCWSTR
    uint cchSource,   // DWORD
    wchar** destOut,   // LPWSTR* out
    uint* cchDestOut   // DWORD* optional, out
);
ccall((:WSDUriEncode, "wsdapi.dll"), stdcall, Int32,
      (Cwstring, UInt32, Ptr{Ptr{UInt16}}, Ptr{UInt32}),
      source, cchSource, destOut, cchDestOut)
# source : LPCWSTR -> Cwstring
# cchSource : DWORD -> UInt32
# destOut : LPWSTR* out -> Ptr{Ptr{UInt16}}
# cchDestOut : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WSDUriEncode(
    const uint16_t* source,
    uint32_t cchSource,
    uint16_t** destOut,
    uint32_t* cchDestOut);
]]
local wsdapi = ffi.load("wsdapi")
-- wsdapi.WSDUriEncode(source, cchSource, destOut, cchDestOut)
-- source : LPCWSTR
-- cchSource : DWORD
-- destOut : LPWSTR* out
-- cchDestOut : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('wsdapi.dll');
const WSDUriEncode = lib.func('__stdcall', 'WSDUriEncode', 'int32_t', ['str16', 'uint32_t', 'void *', 'uint32_t *']);
// WSDUriEncode(source, cchSource, destOut, cchDestOut)
// source : LPCWSTR -> 'str16'
// cchSource : DWORD -> 'uint32_t'
// destOut : LPWSTR* out -> 'void *'
// cchDestOut : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("wsdapi.dll", {
  WSDUriEncode: { parameters: ["buffer", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WSDUriEncode(source, cchSource, destOut, cchDestOut)
// source : LPCWSTR -> "buffer"
// cchSource : DWORD -> "u32"
// destOut : LPWSTR* out -> "pointer"
// cchDestOut : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WSDUriEncode(
    const uint16_t* source,
    uint32_t cchSource,
    uint16_t** destOut,
    uint32_t* cchDestOut);
C, "wsdapi.dll");
// $ffi->WSDUriEncode(source, cchSource, destOut, cchDestOut);
// source : LPCWSTR
// cchSource : DWORD
// destOut : LPWSTR* out
// cchDestOut : DWORD* optional, 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 Wsdapi extends StdCallLibrary {
    Wsdapi INSTANCE = Native.load("wsdapi", Wsdapi.class);
    int WSDUriEncode(
        WString source,   // LPCWSTR
        int cchSource,   // DWORD
        PointerByReference destOut,   // LPWSTR* out
        IntByReference cchDestOut   // DWORD* optional, out
    );
}
@[Link("wsdapi")]
lib Libwsdapi
  fun WSDUriEncode = WSDUriEncode(
    source : UInt16*,   # LPCWSTR
    cchSource : UInt32,   # DWORD
    destOut : UInt16**,   # LPWSTR* out
    cchDestOut : UInt32*   # DWORD* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WSDUriEncodeNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Pointer<Utf16>>, Pointer<Uint32>);
typedef WSDUriEncodeDart = int Function(Pointer<Utf16>, int, Pointer<Pointer<Utf16>>, Pointer<Uint32>);
final WSDUriEncode = DynamicLibrary.open('wsdapi.dll')
    .lookupFunction<WSDUriEncodeNative, WSDUriEncodeDart>('WSDUriEncode');
// source : LPCWSTR -> Pointer<Utf16>
// cchSource : DWORD -> Uint32
// destOut : LPWSTR* out -> Pointer<Pointer<Utf16>>
// cchDestOut : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WSDUriEncode(
  source: PWideChar;   // LPCWSTR
  cchSource: DWORD;   // DWORD
  destOut: PPWideChar;   // LPWSTR* out
  cchDestOut: Pointer   // DWORD* optional, out
): Integer; stdcall;
  external 'wsdapi.dll' name 'WSDUriEncode';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WSDUriEncode"
  c_WSDUriEncode :: CWString -> Word32 -> Ptr CWString -> Ptr Word32 -> IO Int32
-- source : LPCWSTR -> CWString
-- cchSource : DWORD -> Word32
-- destOut : LPWSTR* out -> Ptr CWString
-- cchDestOut : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wsduriencode =
  foreign "WSDUriEncode"
    ((ptr uint16_t) @-> uint32_t @-> (ptr (ptr uint16_t)) @-> (ptr uint32_t) @-> returning int32_t)
(* source : LPCWSTR -> (ptr uint16_t) *)
(* cchSource : DWORD -> uint32_t *)
(* destOut : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* cchDestOut : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wsdapi (t "wsdapi.dll"))
(cffi:use-foreign-library wsdapi)

(cffi:defcfun ("WSDUriEncode" wsduri-encode :convention :stdcall) :int32
  (source (:string :encoding :utf-16le))   ; LPCWSTR
  (cch-source :uint32)   ; DWORD
  (dest-out :pointer)   ; LPWSTR* out
  (cch-dest-out :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WSDUriEncode = Win32::API::More->new('wsdapi',
    'int WSDUriEncode(LPCWSTR source, DWORD cchSource, LPVOID destOut, LPVOID cchDestOut)');
# my $ret = $WSDUriEncode->Call($source, $cchSource, $destOut, $cchDestOut);
# source : LPCWSTR -> LPCWSTR
# cchSource : DWORD -> DWORD
# destOut : LPWSTR* out -> LPVOID
# cchDestOut : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。