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

WsWriteChars

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

シグネチャ

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

HRESULT WsWriteChars(
    WS_XML_WRITER* writer,
    LPCWSTR chars,
    DWORD charCount,
    WS_ERROR* error   // optional
);

パラメーター

名前方向
writerWS_XML_WRITER*in
charsLPCWSTRin
charCountDWORDin
errorWS_ERROR*inoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT WsWriteChars(
    WS_XML_WRITER* writer,
    LPCWSTR chars,
    DWORD charCount,
    WS_ERROR* error   // optional
);
[DllImport("webservices.dll", ExactSpelling = true)]
static extern int WsWriteChars(
    ref IntPtr writer,   // WS_XML_WRITER*
    [MarshalAs(UnmanagedType.LPWStr)] string chars,   // LPCWSTR
    uint charCount,   // DWORD
    IntPtr error   // WS_ERROR* optional
);
<DllImport("webservices.dll", ExactSpelling:=True)>
Public Shared Function WsWriteChars(
    ByRef writer As IntPtr,   ' WS_XML_WRITER*
    <MarshalAs(UnmanagedType.LPWStr)> chars As String,   ' LPCWSTR
    charCount As UInteger,   ' DWORD
    [error] As IntPtr   ' WS_ERROR* optional
) As Integer
End Function
' writer : WS_XML_WRITER*
' chars : LPCWSTR
' charCount : DWORD
' error : WS_ERROR* optional
Declare PtrSafe Function WsWriteChars Lib "webservices" ( _
    ByRef writer As LongPtr, _
    ByVal chars As LongPtr, _
    ByVal charCount 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

WsWriteChars = ctypes.windll.webservices.WsWriteChars
WsWriteChars.restype = ctypes.c_int
WsWriteChars.argtypes = [
    ctypes.c_void_p,  # writer : WS_XML_WRITER*
    wintypes.LPCWSTR,  # chars : LPCWSTR
    wintypes.DWORD,  # charCount : DWORD
    ctypes.c_void_p,  # error : WS_ERROR* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('webservices.dll')
WsWriteChars = Fiddle::Function.new(
  lib['WsWriteChars'],
  [
    Fiddle::TYPE_VOIDP,  # writer : WS_XML_WRITER*
    Fiddle::TYPE_VOIDP,  # chars : LPCWSTR
    -Fiddle::TYPE_INT,  # charCount : DWORD
    Fiddle::TYPE_VOIDP,  # error : WS_ERROR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "webservices")]
extern "system" {
    fn WsWriteChars(
        writer: *mut isize,  // WS_XML_WRITER*
        chars: *const u16,  // LPCWSTR
        charCount: 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 WsWriteChars(ref IntPtr writer, [MarshalAs(UnmanagedType.LPWStr)] string chars, uint charCount, IntPtr error);
"@
$api = Add-Type -MemberDefinition $sig -Name 'webservices_WsWriteChars' -Namespace Win32 -PassThru
# $api::WsWriteChars(writer, chars, charCount, error)
#uselib "webservices.dll"
#func global WsWriteChars "WsWriteChars" sptr, sptr, sptr, sptr
; WsWriteChars writer, chars, charCount, error   ; 戻り値は stat
; writer : WS_XML_WRITER* -> "sptr"
; chars : LPCWSTR -> "sptr"
; charCount : DWORD -> "sptr"
; error : WS_ERROR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "webservices.dll"
#cfunc global WsWriteChars "WsWriteChars" int, wstr, int, int
; res = WsWriteChars(writer, chars, charCount, error)
; writer : WS_XML_WRITER* -> "int"
; chars : LPCWSTR -> "wstr"
; charCount : DWORD -> "int"
; error : WS_ERROR* optional -> "int"
; HRESULT WsWriteChars(WS_XML_WRITER* writer, LPCWSTR chars, DWORD charCount, WS_ERROR* error)
#uselib "webservices.dll"
#cfunc global WsWriteChars "WsWriteChars" int, wstr, int, int
; res = WsWriteChars(writer, chars, charCount, error)
; writer : WS_XML_WRITER* -> "int"
; chars : LPCWSTR -> "wstr"
; charCount : DWORD -> "int"
; error : WS_ERROR* optional -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	webservices = windows.NewLazySystemDLL("webservices.dll")
	procWsWriteChars = webservices.NewProc("WsWriteChars")
)

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