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

WsTrimXmlWhitespace

関数
XML文字列の前後の空白を除去する。
DLLwebservices.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WsTrimXmlWhitespace(
    LPWSTR chars,
    DWORD charCount,
    WORD** trimmedChars,
    DWORD* trimmedCount,
    WS_ERROR* error   // optional
);

パラメーター

名前方向
charsLPWSTRin
charCountDWORDin
trimmedCharsWORD**out
trimmedCountDWORD*out
errorWS_ERROR*inoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

WsTrimXmlWhitespace = ctypes.windll.webservices.WsTrimXmlWhitespace
WsTrimXmlWhitespace.restype = ctypes.c_int
WsTrimXmlWhitespace.argtypes = [
    wintypes.LPCWSTR,  # chars : LPWSTR
    wintypes.DWORD,  # charCount : DWORD
    ctypes.c_void_p,  # trimmedChars : WORD** out
    ctypes.POINTER(wintypes.DWORD),  # trimmedCount : DWORD* out
    ctypes.c_void_p,  # error : WS_ERROR* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('webservices.dll')
WsTrimXmlWhitespace = Fiddle::Function.new(
  lib['WsTrimXmlWhitespace'],
  [
    Fiddle::TYPE_VOIDP,  # chars : LPWSTR
    -Fiddle::TYPE_INT,  # charCount : DWORD
    Fiddle::TYPE_VOIDP,  # trimmedChars : WORD** out
    Fiddle::TYPE_VOIDP,  # trimmedCount : DWORD* out
    Fiddle::TYPE_VOIDP,  # error : WS_ERROR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "webservices")]
extern "system" {
    fn WsTrimXmlWhitespace(
        chars: *mut u16,  // LPWSTR
        charCount: u32,  // DWORD
        trimmedChars: *mut *mut u16,  // WORD** out
        trimmedCount: *mut u32,  // DWORD* out
        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 WsTrimXmlWhitespace([MarshalAs(UnmanagedType.LPWStr)] string chars, uint charCount, IntPtr trimmedChars, out uint trimmedCount, IntPtr error);
"@
$api = Add-Type -MemberDefinition $sig -Name 'webservices_WsTrimXmlWhitespace' -Namespace Win32 -PassThru
# $api::WsTrimXmlWhitespace(chars, charCount, trimmedChars, trimmedCount, error)
#uselib "webservices.dll"
#func global WsTrimXmlWhitespace "WsTrimXmlWhitespace" sptr, sptr, sptr, sptr, sptr
; WsTrimXmlWhitespace chars, charCount, varptr(trimmedChars), varptr(trimmedCount), error   ; 戻り値は stat
; chars : LPWSTR -> "sptr"
; charCount : DWORD -> "sptr"
; trimmedChars : WORD** out -> "sptr"
; trimmedCount : DWORD* out -> "sptr"
; error : WS_ERROR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "webservices.dll"
#cfunc global WsTrimXmlWhitespace "WsTrimXmlWhitespace" wstr, int, var, var, int
; res = WsTrimXmlWhitespace(chars, charCount, trimmedChars, trimmedCount, error)
; chars : LPWSTR -> "wstr"
; charCount : DWORD -> "int"
; trimmedChars : WORD** out -> "var"
; trimmedCount : DWORD* out -> "var"
; error : WS_ERROR* optional -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT WsTrimXmlWhitespace(LPWSTR chars, DWORD charCount, WORD** trimmedChars, DWORD* trimmedCount, WS_ERROR* error)
#uselib "webservices.dll"
#cfunc global WsTrimXmlWhitespace "WsTrimXmlWhitespace" wstr, int, var, var, int
; res = WsTrimXmlWhitespace(chars, charCount, trimmedChars, trimmedCount, error)
; chars : LPWSTR -> "wstr"
; charCount : DWORD -> "int"
; trimmedChars : WORD** out -> "var"
; trimmedCount : DWORD* out -> "var"
; error : WS_ERROR* optional -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	webservices = windows.NewLazySystemDLL("webservices.dll")
	procWsTrimXmlWhitespace = webservices.NewProc("WsTrimXmlWhitespace")
)

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