Win32 API 日本語リファレンス
ホームNetworking.WindowsWebServices › WsWriteCharsUtf8

WsWriteCharsUtf8

関数
XMLにUTF-8文字列を書き込む。
DLLwebservices.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WsWriteCharsUtf8(
    WS_XML_WRITER* writer,
    const BYTE* bytes,
    DWORD byteCount,
    WS_ERROR* error   // optional
);

パラメーター

名前方向
writerWS_XML_WRITER*in
bytesBYTE*in
byteCountDWORDin
errorWS_ERROR*inoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT WsWriteCharsUtf8(
    WS_XML_WRITER* writer,
    const BYTE* bytes,
    DWORD byteCount,
    WS_ERROR* error   // optional
);
[DllImport("webservices.dll", ExactSpelling = true)]
static extern int WsWriteCharsUtf8(
    ref IntPtr writer,   // WS_XML_WRITER*
    IntPtr bytes,   // BYTE*
    uint byteCount,   // DWORD
    IntPtr error   // WS_ERROR* optional
);
<DllImport("webservices.dll", ExactSpelling:=True)>
Public Shared Function WsWriteCharsUtf8(
    ByRef writer As IntPtr,   ' WS_XML_WRITER*
    bytes As IntPtr,   ' BYTE*
    byteCount As UInteger,   ' DWORD
    [error] As IntPtr   ' WS_ERROR* optional
) As Integer
End Function
' writer : WS_XML_WRITER*
' bytes : BYTE*
' byteCount : DWORD
' error : WS_ERROR* optional
Declare PtrSafe Function WsWriteCharsUtf8 Lib "webservices" ( _
    ByRef writer As LongPtr, _
    ByVal bytes As LongPtr, _
    ByVal byteCount As Long, _
    ByVal error As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WsWriteCharsUtf8 = ctypes.windll.webservices.WsWriteCharsUtf8
WsWriteCharsUtf8.restype = ctypes.c_int
WsWriteCharsUtf8.argtypes = [
    ctypes.c_void_p,  # writer : WS_XML_WRITER*
    ctypes.POINTER(ctypes.c_ubyte),  # bytes : BYTE*
    wintypes.DWORD,  # byteCount : DWORD
    ctypes.c_void_p,  # error : WS_ERROR* optional
]
require 'fiddle'
require 'fiddle/import'

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

var (
	webservices = windows.NewLazySystemDLL("webservices.dll")
	procWsWriteCharsUtf8 = webservices.NewProc("WsWriteCharsUtf8")
)

// writer (WS_XML_WRITER*), bytes (BYTE*), byteCount (DWORD), error (WS_ERROR* optional)
r1, _, err := procWsWriteCharsUtf8.Call(
	uintptr(writer),
	uintptr(bytes),
	uintptr(byteCount),
	uintptr(error),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WsWriteCharsUtf8(
  writer: Pointer;   // WS_XML_WRITER*
  bytes: Pointer;   // BYTE*
  byteCount: DWORD;   // DWORD
  error: Pointer   // WS_ERROR* optional
): Integer; stdcall;
  external 'webservices.dll' name 'WsWriteCharsUtf8';
result := DllCall("webservices\WsWriteCharsUtf8"
    , "Ptr", writer   ; WS_XML_WRITER*
    , "Ptr", bytes   ; BYTE*
    , "UInt", byteCount   ; DWORD
    , "Ptr", error   ; WS_ERROR* optional
    , "Int")   ; return: HRESULT
●WsWriteCharsUtf8(writer, bytes, byteCount, error) = DLL("webservices.dll", "int WsWriteCharsUtf8(void*, void*, dword, void*)")
# 呼び出し: WsWriteCharsUtf8(writer, bytes, byteCount, error)
# writer : WS_XML_WRITER* -> "void*"
# bytes : BYTE* -> "void*"
# byteCount : DWORD -> "dword"
# error : WS_ERROR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。