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

WsReceiveMessage

関数
チャネル経由でメッセージを受信する。
DLLwebservices.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT WsReceiveMessage(
    WS_CHANNEL* channel,
    WS_MESSAGE* message,
    const WS_MESSAGE_DESCRIPTION** messageDescriptions,
    DWORD messageDescriptionCount,
    WS_RECEIVE_OPTION receiveOption,
    WS_READ_OPTION readBodyOption,
    WS_HEAP* heap,   // optional
    void* value,
    DWORD valueSize,
    DWORD* index,   // optional
    const WS_ASYNC_CONTEXT* asyncContext,   // optional
    WS_ERROR* error   // optional
);

パラメーター

名前方向説明
channelWS_CHANNEL*inメッセージを受信する対象のチャネル。
messageWS_MESSAGE*in受信に使用するWS_MESSAGEオブジェクト。
messageDescriptionsWS_MESSAGE_DESCRIPTION**in受理可能なメッセージ記述の配列。
messageDescriptionCountDWORDinmessageDescriptions配列の要素数。
receiveOptionWS_RECEIVE_OPTIONinメッセージ必須か任意かを示す受信オプション列挙値。
readBodyOptionWS_READ_OPTIONin本文読み取り方法(必須/任意等)を示す列挙値。
heapWS_HEAP*inoptionalデシリアライズ結果の確保に使うWS_HEAPヒープ。
valuevoid*outデシリアライズした本文を格納する出力バッファ。
valueSizeDWORDinvalueバッファのバイトサイズ。
indexDWORD*outoptional一致したmessageDescriptionsのインデックスを受け取る出力。NULL可。
asyncContextWS_ASYNC_CONTEXT*inoptional非同期実行のためのコンテキスト。同期実行ならNULL。
errorWS_ERROR*inoptional失敗時の追加エラー情報を格納するWS_ERRORオブジェクト。NULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT WsReceiveMessage(
    WS_CHANNEL* channel,
    WS_MESSAGE* message,
    const WS_MESSAGE_DESCRIPTION** messageDescriptions,
    DWORD messageDescriptionCount,
    WS_RECEIVE_OPTION receiveOption,
    WS_READ_OPTION readBodyOption,
    WS_HEAP* heap,   // optional
    void* value,
    DWORD valueSize,
    DWORD* index,   // optional
    const WS_ASYNC_CONTEXT* asyncContext,   // optional
    WS_ERROR* error   // optional
);
[DllImport("webservices.dll", ExactSpelling = true)]
static extern int WsReceiveMessage(
    ref IntPtr channel,   // WS_CHANNEL*
    ref IntPtr message,   // WS_MESSAGE*
    IntPtr messageDescriptions,   // WS_MESSAGE_DESCRIPTION**
    uint messageDescriptionCount,   // DWORD
    int receiveOption,   // WS_RECEIVE_OPTION
    int readBodyOption,   // WS_READ_OPTION
    IntPtr heap,   // WS_HEAP* optional
    IntPtr value,   // void* out
    uint valueSize,   // DWORD
    IntPtr index,   // DWORD* optional, out
    IntPtr asyncContext,   // WS_ASYNC_CONTEXT* optional
    IntPtr error   // WS_ERROR* optional
);
<DllImport("webservices.dll", ExactSpelling:=True)>
Public Shared Function WsReceiveMessage(
    ByRef channel As IntPtr,   ' WS_CHANNEL*
    ByRef message As IntPtr,   ' WS_MESSAGE*
    messageDescriptions As IntPtr,   ' WS_MESSAGE_DESCRIPTION**
    messageDescriptionCount As UInteger,   ' DWORD
    receiveOption As Integer,   ' WS_RECEIVE_OPTION
    readBodyOption As Integer,   ' WS_READ_OPTION
    heap As IntPtr,   ' WS_HEAP* optional
    value As IntPtr,   ' void* out
    valueSize As UInteger,   ' DWORD
    index As IntPtr,   ' DWORD* optional, out
    asyncContext As IntPtr,   ' WS_ASYNC_CONTEXT* optional
    [error] As IntPtr   ' WS_ERROR* optional
) As Integer
End Function
' channel : WS_CHANNEL*
' message : WS_MESSAGE*
' messageDescriptions : WS_MESSAGE_DESCRIPTION**
' messageDescriptionCount : DWORD
' receiveOption : WS_RECEIVE_OPTION
' readBodyOption : WS_READ_OPTION
' heap : WS_HEAP* optional
' value : void* out
' valueSize : DWORD
' index : DWORD* optional, out
' asyncContext : WS_ASYNC_CONTEXT* optional
' error : WS_ERROR* optional
Declare PtrSafe Function WsReceiveMessage Lib "webservices" ( _
    ByRef channel As LongPtr, _
    ByRef message As LongPtr, _
    ByVal messageDescriptions As LongPtr, _
    ByVal messageDescriptionCount As Long, _
    ByVal receiveOption As Long, _
    ByVal readBodyOption As Long, _
    ByVal heap As LongPtr, _
    ByVal value As LongPtr, _
    ByVal valueSize As Long, _
    ByVal index As LongPtr, _
    ByVal asyncContext As LongPtr, _
    ByVal error As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WsReceiveMessage = ctypes.windll.webservices.WsReceiveMessage
WsReceiveMessage.restype = ctypes.c_int
WsReceiveMessage.argtypes = [
    ctypes.c_void_p,  # channel : WS_CHANNEL*
    ctypes.c_void_p,  # message : WS_MESSAGE*
    ctypes.c_void_p,  # messageDescriptions : WS_MESSAGE_DESCRIPTION**
    wintypes.DWORD,  # messageDescriptionCount : DWORD
    ctypes.c_int,  # receiveOption : WS_RECEIVE_OPTION
    ctypes.c_int,  # readBodyOption : WS_READ_OPTION
    ctypes.c_void_p,  # heap : WS_HEAP* optional
    ctypes.POINTER(None),  # value : void* out
    wintypes.DWORD,  # valueSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # index : DWORD* optional, out
    ctypes.c_void_p,  # asyncContext : WS_ASYNC_CONTEXT* optional
    ctypes.c_void_p,  # error : WS_ERROR* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('webservices.dll')
WsReceiveMessage = Fiddle::Function.new(
  lib['WsReceiveMessage'],
  [
    Fiddle::TYPE_VOIDP,  # channel : WS_CHANNEL*
    Fiddle::TYPE_VOIDP,  # message : WS_MESSAGE*
    Fiddle::TYPE_VOIDP,  # messageDescriptions : WS_MESSAGE_DESCRIPTION**
    -Fiddle::TYPE_INT,  # messageDescriptionCount : DWORD
    Fiddle::TYPE_INT,  # receiveOption : WS_RECEIVE_OPTION
    Fiddle::TYPE_INT,  # readBodyOption : WS_READ_OPTION
    Fiddle::TYPE_VOIDP,  # heap : WS_HEAP* optional
    Fiddle::TYPE_VOIDP,  # value : void* out
    -Fiddle::TYPE_INT,  # valueSize : DWORD
    Fiddle::TYPE_VOIDP,  # index : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # asyncContext : WS_ASYNC_CONTEXT* optional
    Fiddle::TYPE_VOIDP,  # error : WS_ERROR* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "webservices")]
extern "system" {
    fn WsReceiveMessage(
        channel: *mut isize,  // WS_CHANNEL*
        message: *mut isize,  // WS_MESSAGE*
        messageDescriptions: *const *const WS_MESSAGE_DESCRIPTION,  // WS_MESSAGE_DESCRIPTION**
        messageDescriptionCount: u32,  // DWORD
        receiveOption: i32,  // WS_RECEIVE_OPTION
        readBodyOption: i32,  // WS_READ_OPTION
        heap: *mut isize,  // WS_HEAP* optional
        value: *mut (),  // void* out
        valueSize: u32,  // DWORD
        index: *mut u32,  // DWORD* optional, out
        asyncContext: *const WS_ASYNC_CONTEXT,  // WS_ASYNC_CONTEXT* optional
        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 WsReceiveMessage(ref IntPtr channel, ref IntPtr message, IntPtr messageDescriptions, uint messageDescriptionCount, int receiveOption, int readBodyOption, IntPtr heap, IntPtr value, uint valueSize, IntPtr index, IntPtr asyncContext, IntPtr error);
"@
$api = Add-Type -MemberDefinition $sig -Name 'webservices_WsReceiveMessage' -Namespace Win32 -PassThru
# $api::WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
#uselib "webservices.dll"
#func global WsReceiveMessage "WsReceiveMessage" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WsReceiveMessage varptr(channel), varptr(message), varptr(messageDescriptions), messageDescriptionCount, receiveOption, readBodyOption, varptr(heap), value, valueSize, varptr(index), varptr(asyncContext), varptr(error)   ; 戻り値は stat
; channel : WS_CHANNEL* -> "sptr"
; message : WS_MESSAGE* -> "sptr"
; messageDescriptions : WS_MESSAGE_DESCRIPTION** -> "sptr"
; messageDescriptionCount : DWORD -> "sptr"
; receiveOption : WS_RECEIVE_OPTION -> "sptr"
; readBodyOption : WS_READ_OPTION -> "sptr"
; heap : WS_HEAP* optional -> "sptr"
; value : void* out -> "sptr"
; valueSize : DWORD -> "sptr"
; index : DWORD* optional, out -> "sptr"
; asyncContext : WS_ASYNC_CONTEXT* optional -> "sptr"
; error : WS_ERROR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "webservices.dll"
#cfunc global WsReceiveMessage "WsReceiveMessage" var, var, var, int, int, int, var, sptr, int, var, var, var
; res = WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
; channel : WS_CHANNEL* -> "var"
; message : WS_MESSAGE* -> "var"
; messageDescriptions : WS_MESSAGE_DESCRIPTION** -> "var"
; messageDescriptionCount : DWORD -> "int"
; receiveOption : WS_RECEIVE_OPTION -> "int"
; readBodyOption : WS_READ_OPTION -> "int"
; heap : WS_HEAP* optional -> "var"
; value : void* out -> "sptr"
; valueSize : DWORD -> "int"
; index : DWORD* optional, out -> "var"
; asyncContext : WS_ASYNC_CONTEXT* optional -> "var"
; error : WS_ERROR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT WsReceiveMessage(WS_CHANNEL* channel, WS_MESSAGE* message, WS_MESSAGE_DESCRIPTION** messageDescriptions, DWORD messageDescriptionCount, WS_RECEIVE_OPTION receiveOption, WS_READ_OPTION readBodyOption, WS_HEAP* heap, void* value, DWORD valueSize, DWORD* index, WS_ASYNC_CONTEXT* asyncContext, WS_ERROR* error)
#uselib "webservices.dll"
#cfunc global WsReceiveMessage "WsReceiveMessage" var, var, var, int, int, int, var, intptr, int, var, var, var
; res = WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
; channel : WS_CHANNEL* -> "var"
; message : WS_MESSAGE* -> "var"
; messageDescriptions : WS_MESSAGE_DESCRIPTION** -> "var"
; messageDescriptionCount : DWORD -> "int"
; receiveOption : WS_RECEIVE_OPTION -> "int"
; readBodyOption : WS_READ_OPTION -> "int"
; heap : WS_HEAP* optional -> "var"
; value : void* out -> "intptr"
; valueSize : DWORD -> "int"
; index : DWORD* optional, out -> "var"
; asyncContext : WS_ASYNC_CONTEXT* optional -> "var"
; error : WS_ERROR* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	webservices = windows.NewLazySystemDLL("webservices.dll")
	procWsReceiveMessage = webservices.NewProc("WsReceiveMessage")
)

// channel (WS_CHANNEL*), message (WS_MESSAGE*), messageDescriptions (WS_MESSAGE_DESCRIPTION**), messageDescriptionCount (DWORD), receiveOption (WS_RECEIVE_OPTION), readBodyOption (WS_READ_OPTION), heap (WS_HEAP* optional), value (void* out), valueSize (DWORD), index (DWORD* optional, out), asyncContext (WS_ASYNC_CONTEXT* optional), error (WS_ERROR* optional)
r1, _, err := procWsReceiveMessage.Call(
	uintptr(channel),
	uintptr(message),
	uintptr(messageDescriptions),
	uintptr(messageDescriptionCount),
	uintptr(receiveOption),
	uintptr(readBodyOption),
	uintptr(heap),
	uintptr(value),
	uintptr(valueSize),
	uintptr(index),
	uintptr(asyncContext),
	uintptr(error),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WsReceiveMessage(
  channel: Pointer;   // WS_CHANNEL*
  message: Pointer;   // WS_MESSAGE*
  messageDescriptions: Pointer;   // WS_MESSAGE_DESCRIPTION**
  messageDescriptionCount: DWORD;   // DWORD
  receiveOption: Integer;   // WS_RECEIVE_OPTION
  readBodyOption: Integer;   // WS_READ_OPTION
  heap: Pointer;   // WS_HEAP* optional
  value: Pointer;   // void* out
  valueSize: DWORD;   // DWORD
  index: Pointer;   // DWORD* optional, out
  asyncContext: Pointer;   // WS_ASYNC_CONTEXT* optional
  error: Pointer   // WS_ERROR* optional
): Integer; stdcall;
  external 'webservices.dll' name 'WsReceiveMessage';
result := DllCall("webservices\WsReceiveMessage"
    , "Ptr", channel   ; WS_CHANNEL*
    , "Ptr", message   ; WS_MESSAGE*
    , "Ptr", messageDescriptions   ; WS_MESSAGE_DESCRIPTION**
    , "UInt", messageDescriptionCount   ; DWORD
    , "Int", receiveOption   ; WS_RECEIVE_OPTION
    , "Int", readBodyOption   ; WS_READ_OPTION
    , "Ptr", heap   ; WS_HEAP* optional
    , "Ptr", value   ; void* out
    , "UInt", valueSize   ; DWORD
    , "Ptr", index   ; DWORD* optional, out
    , "Ptr", asyncContext   ; WS_ASYNC_CONTEXT* optional
    , "Ptr", error   ; WS_ERROR* optional
    , "Int")   ; return: HRESULT
●WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error) = DLL("webservices.dll", "int WsReceiveMessage(void*, void*, void*, dword, int, int, void*, void*, dword, void*, void*, void*)")
# 呼び出し: WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
# channel : WS_CHANNEL* -> "void*"
# message : WS_MESSAGE* -> "void*"
# messageDescriptions : WS_MESSAGE_DESCRIPTION** -> "void*"
# messageDescriptionCount : DWORD -> "dword"
# receiveOption : WS_RECEIVE_OPTION -> "int"
# readBodyOption : WS_READ_OPTION -> "int"
# heap : WS_HEAP* optional -> "void*"
# value : void* out -> "void*"
# valueSize : DWORD -> "dword"
# index : DWORD* optional, out -> "void*"
# asyncContext : WS_ASYNC_CONTEXT* optional -> "void*"
# error : WS_ERROR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "webservices" fn WsReceiveMessage(
    channel: [*c]isize, // WS_CHANNEL*
    message: [*c]isize, // WS_MESSAGE*
    messageDescriptions: [*c][*c]WS_MESSAGE_DESCRIPTION, // WS_MESSAGE_DESCRIPTION**
    messageDescriptionCount: u32, // DWORD
    receiveOption: i32, // WS_RECEIVE_OPTION
    readBodyOption: i32, // WS_READ_OPTION
    heap: [*c]isize, // WS_HEAP* optional
    value: ?*anyopaque, // void* out
    valueSize: u32, // DWORD
    index: [*c]u32, // DWORD* optional, out
    asyncContext: [*c]WS_ASYNC_CONTEXT, // WS_ASYNC_CONTEXT* optional
    error: [*c]isize // WS_ERROR* optional
) callconv(std.os.windows.WINAPI) i32;
proc WsReceiveMessage(
    channel: ptr int,  # WS_CHANNEL*
    message: ptr int,  # WS_MESSAGE*
    messageDescriptions: ptr WS_MESSAGE_DESCRIPTION,  # WS_MESSAGE_DESCRIPTION**
    messageDescriptionCount: uint32,  # DWORD
    receiveOption: int32,  # WS_RECEIVE_OPTION
    readBodyOption: int32,  # WS_READ_OPTION
    heap: ptr int,  # WS_HEAP* optional
    value: pointer,  # void* out
    valueSize: uint32,  # DWORD
    index: ptr uint32,  # DWORD* optional, out
    asyncContext: ptr WS_ASYNC_CONTEXT,  # WS_ASYNC_CONTEXT* optional
    error: ptr int  # WS_ERROR* optional
): int32 {.importc: "WsReceiveMessage", stdcall, dynlib: "webservices.dll".}
pragma(lib, "webservices");
extern(Windows)
int WsReceiveMessage(
    ptrdiff_t* channel,   // WS_CHANNEL*
    ptrdiff_t* message,   // WS_MESSAGE*
    WS_MESSAGE_DESCRIPTION** messageDescriptions,   // WS_MESSAGE_DESCRIPTION**
    uint messageDescriptionCount,   // DWORD
    int receiveOption,   // WS_RECEIVE_OPTION
    int readBodyOption,   // WS_READ_OPTION
    ptrdiff_t* heap,   // WS_HEAP* optional
    void* value,   // void* out
    uint valueSize,   // DWORD
    uint* index,   // DWORD* optional, out
    WS_ASYNC_CONTEXT* asyncContext,   // WS_ASYNC_CONTEXT* optional
    ptrdiff_t* error   // WS_ERROR* optional
);
ccall((:WsReceiveMessage, "webservices.dll"), stdcall, Int32,
      (Ptr{Int}, Ptr{Int}, Ptr{WS_MESSAGE_DESCRIPTION}, UInt32, Int32, Int32, Ptr{Int}, Ptr{Cvoid}, UInt32, Ptr{UInt32}, Ptr{WS_ASYNC_CONTEXT}, Ptr{Int}),
      channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
# channel : WS_CHANNEL* -> Ptr{Int}
# message : WS_MESSAGE* -> Ptr{Int}
# messageDescriptions : WS_MESSAGE_DESCRIPTION** -> Ptr{WS_MESSAGE_DESCRIPTION}
# messageDescriptionCount : DWORD -> UInt32
# receiveOption : WS_RECEIVE_OPTION -> Int32
# readBodyOption : WS_READ_OPTION -> Int32
# heap : WS_HEAP* optional -> Ptr{Int}
# value : void* out -> Ptr{Cvoid}
# valueSize : DWORD -> UInt32
# index : DWORD* optional, out -> Ptr{UInt32}
# asyncContext : WS_ASYNC_CONTEXT* optional -> Ptr{WS_ASYNC_CONTEXT}
# error : WS_ERROR* optional -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WsReceiveMessage(
    intptr_t* channel,
    intptr_t* message,
    void* messageDescriptions,
    uint32_t messageDescriptionCount,
    int32_t receiveOption,
    int32_t readBodyOption,
    intptr_t* heap,
    void* value,
    uint32_t valueSize,
    uint32_t* index,
    void* asyncContext,
    intptr_t* error);
]]
local webservices = ffi.load("webservices")
-- webservices.WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
-- channel : WS_CHANNEL*
-- message : WS_MESSAGE*
-- messageDescriptions : WS_MESSAGE_DESCRIPTION**
-- messageDescriptionCount : DWORD
-- receiveOption : WS_RECEIVE_OPTION
-- readBodyOption : WS_READ_OPTION
-- heap : WS_HEAP* optional
-- value : void* out
-- valueSize : DWORD
-- index : DWORD* optional, out
-- asyncContext : WS_ASYNC_CONTEXT* optional
-- error : WS_ERROR* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('webservices.dll');
const WsReceiveMessage = lib.func('__stdcall', 'WsReceiveMessage', 'int32_t', ['intptr_t *', 'intptr_t *', 'void *', 'uint32_t', 'int32_t', 'int32_t', 'intptr_t *', 'void *', 'uint32_t', 'uint32_t *', 'void *', 'intptr_t *']);
// WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
// channel : WS_CHANNEL* -> 'intptr_t *'
// message : WS_MESSAGE* -> 'intptr_t *'
// messageDescriptions : WS_MESSAGE_DESCRIPTION** -> 'void *'
// messageDescriptionCount : DWORD -> 'uint32_t'
// receiveOption : WS_RECEIVE_OPTION -> 'int32_t'
// readBodyOption : WS_READ_OPTION -> 'int32_t'
// heap : WS_HEAP* optional -> 'intptr_t *'
// value : void* out -> 'void *'
// valueSize : DWORD -> 'uint32_t'
// index : DWORD* optional, out -> 'uint32_t *'
// asyncContext : WS_ASYNC_CONTEXT* optional -> 'void *'
// error : WS_ERROR* optional -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("webservices.dll", {
  WsReceiveMessage: { parameters: ["pointer", "pointer", "pointer", "u32", "i32", "i32", "pointer", "pointer", "u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error)
// channel : WS_CHANNEL* -> "pointer"
// message : WS_MESSAGE* -> "pointer"
// messageDescriptions : WS_MESSAGE_DESCRIPTION** -> "pointer"
// messageDescriptionCount : DWORD -> "u32"
// receiveOption : WS_RECEIVE_OPTION -> "i32"
// readBodyOption : WS_READ_OPTION -> "i32"
// heap : WS_HEAP* optional -> "pointer"
// value : void* out -> "pointer"
// valueSize : DWORD -> "u32"
// index : DWORD* optional, out -> "pointer"
// asyncContext : WS_ASYNC_CONTEXT* optional -> "pointer"
// error : WS_ERROR* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WsReceiveMessage(
    intptr_t* channel,
    intptr_t* message,
    void* messageDescriptions,
    uint32_t messageDescriptionCount,
    int32_t receiveOption,
    int32_t readBodyOption,
    intptr_t* heap,
    void* value,
    uint32_t valueSize,
    uint32_t* index,
    void* asyncContext,
    intptr_t* error);
C, "webservices.dll");
// $ffi->WsReceiveMessage(channel, message, messageDescriptions, messageDescriptionCount, receiveOption, readBodyOption, heap, value, valueSize, index, asyncContext, error);
// channel : WS_CHANNEL*
// message : WS_MESSAGE*
// messageDescriptions : WS_MESSAGE_DESCRIPTION**
// messageDescriptionCount : DWORD
// receiveOption : WS_RECEIVE_OPTION
// readBodyOption : WS_READ_OPTION
// heap : WS_HEAP* optional
// value : void* out
// valueSize : DWORD
// index : DWORD* optional, out
// asyncContext : WS_ASYNC_CONTEXT* optional
// error : WS_ERROR* optional
// 構造体/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 Webservices extends StdCallLibrary {
    Webservices INSTANCE = Native.load("webservices", Webservices.class);
    int WsReceiveMessage(
        LongByReference channel,   // WS_CHANNEL*
        LongByReference message,   // WS_MESSAGE*
        Pointer messageDescriptions,   // WS_MESSAGE_DESCRIPTION**
        int messageDescriptionCount,   // DWORD
        int receiveOption,   // WS_RECEIVE_OPTION
        int readBodyOption,   // WS_READ_OPTION
        LongByReference heap,   // WS_HEAP* optional
        Pointer value,   // void* out
        int valueSize,   // DWORD
        IntByReference index,   // DWORD* optional, out
        Pointer asyncContext,   // WS_ASYNC_CONTEXT* optional
        LongByReference error   // WS_ERROR* optional
    );
}
@[Link("webservices")]
lib Libwebservices
  fun WsReceiveMessage = WsReceiveMessage(
    channel : LibC::SSizeT*,   # WS_CHANNEL*
    message : LibC::SSizeT*,   # WS_MESSAGE*
    messageDescriptions : WS_MESSAGE_DESCRIPTION**,   # WS_MESSAGE_DESCRIPTION**
    messageDescriptionCount : UInt32,   # DWORD
    receiveOption : Int32,   # WS_RECEIVE_OPTION
    readBodyOption : Int32,   # WS_READ_OPTION
    heap : LibC::SSizeT*,   # WS_HEAP* optional
    value : Void*,   # void* out
    valueSize : UInt32,   # DWORD
    index : UInt32*,   # DWORD* optional, out
    asyncContext : WS_ASYNC_CONTEXT*,   # WS_ASYNC_CONTEXT* optional
    error : LibC::SSizeT*   # WS_ERROR* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WsReceiveMessageNative = Int32 Function(Pointer<IntPtr>, Pointer<IntPtr>, Pointer<Void>, Uint32, Int32, Int32, Pointer<IntPtr>, Pointer<Void>, Uint32, Pointer<Uint32>, Pointer<Void>, Pointer<IntPtr>);
typedef WsReceiveMessageDart = int Function(Pointer<IntPtr>, Pointer<IntPtr>, Pointer<Void>, int, int, int, Pointer<IntPtr>, Pointer<Void>, int, Pointer<Uint32>, Pointer<Void>, Pointer<IntPtr>);
final WsReceiveMessage = DynamicLibrary.open('webservices.dll')
    .lookupFunction<WsReceiveMessageNative, WsReceiveMessageDart>('WsReceiveMessage');
// channel : WS_CHANNEL* -> Pointer<IntPtr>
// message : WS_MESSAGE* -> Pointer<IntPtr>
// messageDescriptions : WS_MESSAGE_DESCRIPTION** -> Pointer<Void>
// messageDescriptionCount : DWORD -> Uint32
// receiveOption : WS_RECEIVE_OPTION -> Int32
// readBodyOption : WS_READ_OPTION -> Int32
// heap : WS_HEAP* optional -> Pointer<IntPtr>
// value : void* out -> Pointer<Void>
// valueSize : DWORD -> Uint32
// index : DWORD* optional, out -> Pointer<Uint32>
// asyncContext : WS_ASYNC_CONTEXT* optional -> Pointer<Void>
// error : WS_ERROR* optional -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WsReceiveMessage(
  channel: Pointer;   // WS_CHANNEL*
  message: Pointer;   // WS_MESSAGE*
  messageDescriptions: Pointer;   // WS_MESSAGE_DESCRIPTION**
  messageDescriptionCount: DWORD;   // DWORD
  receiveOption: Integer;   // WS_RECEIVE_OPTION
  readBodyOption: Integer;   // WS_READ_OPTION
  heap: Pointer;   // WS_HEAP* optional
  value: Pointer;   // void* out
  valueSize: DWORD;   // DWORD
  index: Pointer;   // DWORD* optional, out
  asyncContext: Pointer;   // WS_ASYNC_CONTEXT* optional
  error: Pointer   // WS_ERROR* optional
): Integer; stdcall;
  external 'webservices.dll' name 'WsReceiveMessage';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WsReceiveMessage"
  c_WsReceiveMessage :: Ptr CIntPtr -> Ptr CIntPtr -> Ptr () -> Word32 -> Int32 -> Int32 -> Ptr CIntPtr -> Ptr () -> Word32 -> Ptr Word32 -> Ptr () -> Ptr CIntPtr -> IO Int32
-- channel : WS_CHANNEL* -> Ptr CIntPtr
-- message : WS_MESSAGE* -> Ptr CIntPtr
-- messageDescriptions : WS_MESSAGE_DESCRIPTION** -> Ptr ()
-- messageDescriptionCount : DWORD -> Word32
-- receiveOption : WS_RECEIVE_OPTION -> Int32
-- readBodyOption : WS_READ_OPTION -> Int32
-- heap : WS_HEAP* optional -> Ptr CIntPtr
-- value : void* out -> Ptr ()
-- valueSize : DWORD -> Word32
-- index : DWORD* optional, out -> Ptr Word32
-- asyncContext : WS_ASYNC_CONTEXT* optional -> Ptr ()
-- error : WS_ERROR* optional -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wsreceivemessage =
  foreign "WsReceiveMessage"
    ((ptr intptr_t) @-> (ptr intptr_t) @-> (ptr void) @-> uint32_t @-> int32_t @-> int32_t @-> (ptr intptr_t) @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> (ptr void) @-> (ptr intptr_t) @-> returning int32_t)
(* channel : WS_CHANNEL* -> (ptr intptr_t) *)
(* message : WS_MESSAGE* -> (ptr intptr_t) *)
(* messageDescriptions : WS_MESSAGE_DESCRIPTION** -> (ptr void) *)
(* messageDescriptionCount : DWORD -> uint32_t *)
(* receiveOption : WS_RECEIVE_OPTION -> int32_t *)
(* readBodyOption : WS_READ_OPTION -> int32_t *)
(* heap : WS_HEAP* optional -> (ptr intptr_t) *)
(* value : void* out -> (ptr void) *)
(* valueSize : DWORD -> uint32_t *)
(* index : DWORD* optional, out -> (ptr uint32_t) *)
(* asyncContext : WS_ASYNC_CONTEXT* optional -> (ptr void) *)
(* error : WS_ERROR* optional -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library webservices (t "webservices.dll"))
(cffi:use-foreign-library webservices)

(cffi:defcfun ("WsReceiveMessage" ws-receive-message :convention :stdcall) :int32
  (channel :pointer)   ; WS_CHANNEL*
  (message :pointer)   ; WS_MESSAGE*
  (message-descriptions :pointer)   ; WS_MESSAGE_DESCRIPTION**
  (message-description-count :uint32)   ; DWORD
  (receive-option :int32)   ; WS_RECEIVE_OPTION
  (read-body-option :int32)   ; WS_READ_OPTION
  (heap :pointer)   ; WS_HEAP* optional
  (value :pointer)   ; void* out
  (value-size :uint32)   ; DWORD
  (index :pointer)   ; DWORD* optional, out
  (async-context :pointer)   ; WS_ASYNC_CONTEXT* optional
  (error :pointer))   ; WS_ERROR* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WsReceiveMessage = Win32::API::More->new('webservices',
    'int WsReceiveMessage(LPVOID channel, LPVOID message, LPVOID messageDescriptions, DWORD messageDescriptionCount, int receiveOption, int readBodyOption, LPVOID heap, LPVOID value, DWORD valueSize, LPVOID index, LPVOID asyncContext, LPVOID error)');
# my $ret = $WsReceiveMessage->Call($channel, $message, $messageDescriptions, $messageDescriptionCount, $receiveOption, $readBodyOption, $heap, $value, $valueSize, $index, $asyncContext, $error);
# channel : WS_CHANNEL* -> LPVOID
# message : WS_MESSAGE* -> LPVOID
# messageDescriptions : WS_MESSAGE_DESCRIPTION** -> LPVOID
# messageDescriptionCount : DWORD -> DWORD
# receiveOption : WS_RECEIVE_OPTION -> int
# readBodyOption : WS_READ_OPTION -> int
# heap : WS_HEAP* optional -> LPVOID
# value : void* out -> LPVOID
# valueSize : DWORD -> DWORD
# index : DWORD* optional, out -> LPVOID
# asyncContext : WS_ASYNC_CONTEXT* optional -> LPVOID
# error : WS_ERROR* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型