ホーム › System.MessageQueuing › MQReceiveMessage
MQReceiveMessage
関数キューからメッセージを受信または閲覧する。
シグネチャ
// mqrt.dll
#include <windows.h>
HRESULT MQReceiveMessage(
INT_PTR hSource,
DWORD dwTimeout,
DWORD dwAction,
MQMSGPROPS* pMessageProps, // optional
OVERLAPPED* lpOverlapped, // optional
PMQRECEIVECALLBACK fnReceiveCallback, // optional
HANDLE hCursor, // optional
ITransaction* pTransaction // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hSource | INT_PTR | in | 受信元となる開いているキューのハンドルを指定する。 |
| dwTimeout | DWORD | in | 受信を待機する最大時間(ミリ秒)。INFINITEで無期限待機となる。 |
| dwAction | DWORD | in | 受信動作。MQ_ACTION_RECEIVE(取り出し)やMQ_ACTION_PEEK_CURRENT(覗き見)等を指定する。 |
| pMessageProps | MQMSGPROPS* | inoutoptional | 受信したメッセージのプロパティを受け取るMQMSGPROPS構造体へのポインタを指定する。 |
| lpOverlapped | OVERLAPPED* | inoutoptional | 非同期受信に使うOVERLAPPED構造体へのポインタ。NULL可で同期受信となる。 |
| fnReceiveCallback | PMQRECEIVECALLBACK | inoptional | 非同期完了時に呼ばれる受信コールバック関数へのポインタ。NULL可。 |
| hCursor | HANDLE | inoptional | 順次受信に使うカーソルハンドル。NULL可でキュー先頭基準となる。 |
| pTransaction | ITransaction* | inoptional | 受信を実行するトランザクションへのITransactionポインタ。NULLや特殊定数で非トランザクション受信となる。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// mqrt.dll
#include <windows.h>
HRESULT MQReceiveMessage(
INT_PTR hSource,
DWORD dwTimeout,
DWORD dwAction,
MQMSGPROPS* pMessageProps, // optional
OVERLAPPED* lpOverlapped, // optional
PMQRECEIVECALLBACK fnReceiveCallback, // optional
HANDLE hCursor, // optional
ITransaction* pTransaction // optional
);[DllImport("mqrt.dll", ExactSpelling = true)]
static extern int MQReceiveMessage(
IntPtr hSource, // INT_PTR
uint dwTimeout, // DWORD
uint dwAction, // DWORD
IntPtr pMessageProps, // MQMSGPROPS* optional, in/out
IntPtr lpOverlapped, // OVERLAPPED* optional, in/out
IntPtr fnReceiveCallback, // PMQRECEIVECALLBACK optional
IntPtr hCursor, // HANDLE optional
IntPtr pTransaction // ITransaction* optional
);<DllImport("mqrt.dll", ExactSpelling:=True)>
Public Shared Function MQReceiveMessage(
hSource As IntPtr, ' INT_PTR
dwTimeout As UInteger, ' DWORD
dwAction As UInteger, ' DWORD
pMessageProps As IntPtr, ' MQMSGPROPS* optional, in/out
lpOverlapped As IntPtr, ' OVERLAPPED* optional, in/out
fnReceiveCallback As IntPtr, ' PMQRECEIVECALLBACK optional
hCursor As IntPtr, ' HANDLE optional
pTransaction As IntPtr ' ITransaction* optional
) As Integer
End Function' hSource : INT_PTR
' dwTimeout : DWORD
' dwAction : DWORD
' pMessageProps : MQMSGPROPS* optional, in/out
' lpOverlapped : OVERLAPPED* optional, in/out
' fnReceiveCallback : PMQRECEIVECALLBACK optional
' hCursor : HANDLE optional
' pTransaction : ITransaction* optional
Declare PtrSafe Function MQReceiveMessage Lib "mqrt" ( _
ByVal hSource As LongPtr, _
ByVal dwTimeout As Long, _
ByVal dwAction As Long, _
ByVal pMessageProps As LongPtr, _
ByVal lpOverlapped As LongPtr, _
ByVal fnReceiveCallback As LongPtr, _
ByVal hCursor As LongPtr, _
ByVal pTransaction As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MQReceiveMessage = ctypes.windll.mqrt.MQReceiveMessage
MQReceiveMessage.restype = ctypes.c_int
MQReceiveMessage.argtypes = [
ctypes.c_ssize_t, # hSource : INT_PTR
wintypes.DWORD, # dwTimeout : DWORD
wintypes.DWORD, # dwAction : DWORD
ctypes.c_void_p, # pMessageProps : MQMSGPROPS* optional, in/out
ctypes.c_void_p, # lpOverlapped : OVERLAPPED* optional, in/out
ctypes.c_void_p, # fnReceiveCallback : PMQRECEIVECALLBACK optional
wintypes.HANDLE, # hCursor : HANDLE optional
ctypes.c_void_p, # pTransaction : ITransaction* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mqrt.dll')
MQReceiveMessage = Fiddle::Function.new(
lib['MQReceiveMessage'],
[
Fiddle::TYPE_INTPTR_T, # hSource : INT_PTR
-Fiddle::TYPE_INT, # dwTimeout : DWORD
-Fiddle::TYPE_INT, # dwAction : DWORD
Fiddle::TYPE_VOIDP, # pMessageProps : MQMSGPROPS* optional, in/out
Fiddle::TYPE_VOIDP, # lpOverlapped : OVERLAPPED* optional, in/out
Fiddle::TYPE_VOIDP, # fnReceiveCallback : PMQRECEIVECALLBACK optional
Fiddle::TYPE_VOIDP, # hCursor : HANDLE optional
Fiddle::TYPE_VOIDP, # pTransaction : ITransaction* optional
],
Fiddle::TYPE_INT)#[link(name = "mqrt")]
extern "system" {
fn MQReceiveMessage(
hSource: isize, // INT_PTR
dwTimeout: u32, // DWORD
dwAction: u32, // DWORD
pMessageProps: *mut MQMSGPROPS, // MQMSGPROPS* optional, in/out
lpOverlapped: *mut OVERLAPPED, // OVERLAPPED* optional, in/out
fnReceiveCallback: *const core::ffi::c_void, // PMQRECEIVECALLBACK optional
hCursor: *mut core::ffi::c_void, // HANDLE optional
pTransaction: *mut core::ffi::c_void // ITransaction* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("mqrt.dll")]
public static extern int MQReceiveMessage(IntPtr hSource, uint dwTimeout, uint dwAction, IntPtr pMessageProps, IntPtr lpOverlapped, IntPtr fnReceiveCallback, IntPtr hCursor, IntPtr pTransaction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mqrt_MQReceiveMessage' -Namespace Win32 -PassThru
# $api::MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction)#uselib "mqrt.dll"
#func global MQReceiveMessage "MQReceiveMessage" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; MQReceiveMessage hSource, dwTimeout, dwAction, varptr(pMessageProps), varptr(lpOverlapped), fnReceiveCallback, hCursor, pTransaction ; 戻り値は stat
; hSource : INT_PTR -> "sptr"
; dwTimeout : DWORD -> "sptr"
; dwAction : DWORD -> "sptr"
; pMessageProps : MQMSGPROPS* optional, in/out -> "sptr"
; lpOverlapped : OVERLAPPED* optional, in/out -> "sptr"
; fnReceiveCallback : PMQRECEIVECALLBACK optional -> "sptr"
; hCursor : HANDLE optional -> "sptr"
; pTransaction : ITransaction* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "mqrt.dll" #cfunc global MQReceiveMessage "MQReceiveMessage" sptr, int, int, var, var, sptr, sptr, sptr ; res = MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction) ; hSource : INT_PTR -> "sptr" ; dwTimeout : DWORD -> "int" ; dwAction : DWORD -> "int" ; pMessageProps : MQMSGPROPS* optional, in/out -> "var" ; lpOverlapped : OVERLAPPED* optional, in/out -> "var" ; fnReceiveCallback : PMQRECEIVECALLBACK optional -> "sptr" ; hCursor : HANDLE optional -> "sptr" ; pTransaction : ITransaction* optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "mqrt.dll" #cfunc global MQReceiveMessage "MQReceiveMessage" sptr, int, int, sptr, sptr, sptr, sptr, sptr ; res = MQReceiveMessage(hSource, dwTimeout, dwAction, varptr(pMessageProps), varptr(lpOverlapped), fnReceiveCallback, hCursor, pTransaction) ; hSource : INT_PTR -> "sptr" ; dwTimeout : DWORD -> "int" ; dwAction : DWORD -> "int" ; pMessageProps : MQMSGPROPS* optional, in/out -> "sptr" ; lpOverlapped : OVERLAPPED* optional, in/out -> "sptr" ; fnReceiveCallback : PMQRECEIVECALLBACK optional -> "sptr" ; hCursor : HANDLE optional -> "sptr" ; pTransaction : ITransaction* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT MQReceiveMessage(INT_PTR hSource, DWORD dwTimeout, DWORD dwAction, MQMSGPROPS* pMessageProps, OVERLAPPED* lpOverlapped, PMQRECEIVECALLBACK fnReceiveCallback, HANDLE hCursor, ITransaction* pTransaction) #uselib "mqrt.dll" #cfunc global MQReceiveMessage "MQReceiveMessage" intptr, int, int, var, var, intptr, intptr, intptr ; res = MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction) ; hSource : INT_PTR -> "intptr" ; dwTimeout : DWORD -> "int" ; dwAction : DWORD -> "int" ; pMessageProps : MQMSGPROPS* optional, in/out -> "var" ; lpOverlapped : OVERLAPPED* optional, in/out -> "var" ; fnReceiveCallback : PMQRECEIVECALLBACK optional -> "intptr" ; hCursor : HANDLE optional -> "intptr" ; pTransaction : ITransaction* optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT MQReceiveMessage(INT_PTR hSource, DWORD dwTimeout, DWORD dwAction, MQMSGPROPS* pMessageProps, OVERLAPPED* lpOverlapped, PMQRECEIVECALLBACK fnReceiveCallback, HANDLE hCursor, ITransaction* pTransaction) #uselib "mqrt.dll" #cfunc global MQReceiveMessage "MQReceiveMessage" intptr, int, int, intptr, intptr, intptr, intptr, intptr ; res = MQReceiveMessage(hSource, dwTimeout, dwAction, varptr(pMessageProps), varptr(lpOverlapped), fnReceiveCallback, hCursor, pTransaction) ; hSource : INT_PTR -> "intptr" ; dwTimeout : DWORD -> "int" ; dwAction : DWORD -> "int" ; pMessageProps : MQMSGPROPS* optional, in/out -> "intptr" ; lpOverlapped : OVERLAPPED* optional, in/out -> "intptr" ; fnReceiveCallback : PMQRECEIVECALLBACK optional -> "intptr" ; hCursor : HANDLE optional -> "intptr" ; pTransaction : ITransaction* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mqrt = windows.NewLazySystemDLL("mqrt.dll")
procMQReceiveMessage = mqrt.NewProc("MQReceiveMessage")
)
// hSource (INT_PTR), dwTimeout (DWORD), dwAction (DWORD), pMessageProps (MQMSGPROPS* optional, in/out), lpOverlapped (OVERLAPPED* optional, in/out), fnReceiveCallback (PMQRECEIVECALLBACK optional), hCursor (HANDLE optional), pTransaction (ITransaction* optional)
r1, _, err := procMQReceiveMessage.Call(
uintptr(hSource),
uintptr(dwTimeout),
uintptr(dwAction),
uintptr(pMessageProps),
uintptr(lpOverlapped),
uintptr(fnReceiveCallback),
uintptr(hCursor),
uintptr(pTransaction),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction MQReceiveMessage(
hSource: NativeInt; // INT_PTR
dwTimeout: DWORD; // DWORD
dwAction: DWORD; // DWORD
pMessageProps: Pointer; // MQMSGPROPS* optional, in/out
lpOverlapped: Pointer; // OVERLAPPED* optional, in/out
fnReceiveCallback: Pointer; // PMQRECEIVECALLBACK optional
hCursor: THandle; // HANDLE optional
pTransaction: Pointer // ITransaction* optional
): Integer; stdcall;
external 'mqrt.dll' name 'MQReceiveMessage';result := DllCall("mqrt\MQReceiveMessage"
, "Ptr", hSource ; INT_PTR
, "UInt", dwTimeout ; DWORD
, "UInt", dwAction ; DWORD
, "Ptr", pMessageProps ; MQMSGPROPS* optional, in/out
, "Ptr", lpOverlapped ; OVERLAPPED* optional, in/out
, "Ptr", fnReceiveCallback ; PMQRECEIVECALLBACK optional
, "Ptr", hCursor ; HANDLE optional
, "Ptr", pTransaction ; ITransaction* optional
, "Int") ; return: HRESULT●MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction) = DLL("mqrt.dll", "int MQReceiveMessage(int, dword, dword, void*, void*, void*, void*, void*)")
# 呼び出し: MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction)
# hSource : INT_PTR -> "int"
# dwTimeout : DWORD -> "dword"
# dwAction : DWORD -> "dword"
# pMessageProps : MQMSGPROPS* optional, in/out -> "void*"
# lpOverlapped : OVERLAPPED* optional, in/out -> "void*"
# fnReceiveCallback : PMQRECEIVECALLBACK optional -> "void*"
# hCursor : HANDLE optional -> "void*"
# pTransaction : ITransaction* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mqrt" fn MQReceiveMessage(
hSource: isize, // INT_PTR
dwTimeout: u32, // DWORD
dwAction: u32, // DWORD
pMessageProps: [*c]MQMSGPROPS, // MQMSGPROPS* optional, in/out
lpOverlapped: [*c]OVERLAPPED, // OVERLAPPED* optional, in/out
fnReceiveCallback: ?*anyopaque, // PMQRECEIVECALLBACK optional
hCursor: ?*anyopaque, // HANDLE optional
pTransaction: ?*anyopaque // ITransaction* optional
) callconv(std.os.windows.WINAPI) i32;proc MQReceiveMessage(
hSource: int, # INT_PTR
dwTimeout: uint32, # DWORD
dwAction: uint32, # DWORD
pMessageProps: ptr MQMSGPROPS, # MQMSGPROPS* optional, in/out
lpOverlapped: ptr OVERLAPPED, # OVERLAPPED* optional, in/out
fnReceiveCallback: pointer, # PMQRECEIVECALLBACK optional
hCursor: pointer, # HANDLE optional
pTransaction: pointer # ITransaction* optional
): int32 {.importc: "MQReceiveMessage", stdcall, dynlib: "mqrt.dll".}pragma(lib, "mqrt");
extern(Windows)
int MQReceiveMessage(
ptrdiff_t hSource, // INT_PTR
uint dwTimeout, // DWORD
uint dwAction, // DWORD
MQMSGPROPS* pMessageProps, // MQMSGPROPS* optional, in/out
OVERLAPPED* lpOverlapped, // OVERLAPPED* optional, in/out
void* fnReceiveCallback, // PMQRECEIVECALLBACK optional
void* hCursor, // HANDLE optional
void* pTransaction // ITransaction* optional
);ccall((:MQReceiveMessage, "mqrt.dll"), stdcall, Int32,
(Int, UInt32, UInt32, Ptr{MQMSGPROPS}, Ptr{OVERLAPPED}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction)
# hSource : INT_PTR -> Int
# dwTimeout : DWORD -> UInt32
# dwAction : DWORD -> UInt32
# pMessageProps : MQMSGPROPS* optional, in/out -> Ptr{MQMSGPROPS}
# lpOverlapped : OVERLAPPED* optional, in/out -> Ptr{OVERLAPPED}
# fnReceiveCallback : PMQRECEIVECALLBACK optional -> Ptr{Cvoid}
# hCursor : HANDLE optional -> Ptr{Cvoid}
# pTransaction : ITransaction* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t MQReceiveMessage(
intptr_t hSource,
uint32_t dwTimeout,
uint32_t dwAction,
void* pMessageProps,
void* lpOverlapped,
void* fnReceiveCallback,
void* hCursor,
void* pTransaction);
]]
local mqrt = ffi.load("mqrt")
-- mqrt.MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction)
-- hSource : INT_PTR
-- dwTimeout : DWORD
-- dwAction : DWORD
-- pMessageProps : MQMSGPROPS* optional, in/out
-- lpOverlapped : OVERLAPPED* optional, in/out
-- fnReceiveCallback : PMQRECEIVECALLBACK optional
-- hCursor : HANDLE optional
-- pTransaction : ITransaction* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mqrt.dll');
const MQReceiveMessage = lib.func('__stdcall', 'MQReceiveMessage', 'int32_t', ['intptr_t', 'uint32_t', 'uint32_t', 'void *', 'void *', 'void *', 'void *', 'void *']);
// MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction)
// hSource : INT_PTR -> 'intptr_t'
// dwTimeout : DWORD -> 'uint32_t'
// dwAction : DWORD -> 'uint32_t'
// pMessageProps : MQMSGPROPS* optional, in/out -> 'void *'
// lpOverlapped : OVERLAPPED* optional, in/out -> 'void *'
// fnReceiveCallback : PMQRECEIVECALLBACK optional -> 'void *'
// hCursor : HANDLE optional -> 'void *'
// pTransaction : ITransaction* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("mqrt.dll", {
MQReceiveMessage: { parameters: ["isize", "u32", "u32", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction)
// hSource : INT_PTR -> "isize"
// dwTimeout : DWORD -> "u32"
// dwAction : DWORD -> "u32"
// pMessageProps : MQMSGPROPS* optional, in/out -> "pointer"
// lpOverlapped : OVERLAPPED* optional, in/out -> "pointer"
// fnReceiveCallback : PMQRECEIVECALLBACK optional -> "pointer"
// hCursor : HANDLE optional -> "pointer"
// pTransaction : ITransaction* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t MQReceiveMessage(
intptr_t hSource,
uint32_t dwTimeout,
uint32_t dwAction,
void* pMessageProps,
void* lpOverlapped,
void* fnReceiveCallback,
void* hCursor,
void* pTransaction);
C, "mqrt.dll");
// $ffi->MQReceiveMessage(hSource, dwTimeout, dwAction, pMessageProps, lpOverlapped, fnReceiveCallback, hCursor, pTransaction);
// hSource : INT_PTR
// dwTimeout : DWORD
// dwAction : DWORD
// pMessageProps : MQMSGPROPS* optional, in/out
// lpOverlapped : OVERLAPPED* optional, in/out
// fnReceiveCallback : PMQRECEIVECALLBACK optional
// hCursor : HANDLE optional
// pTransaction : ITransaction* 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 Mqrt extends StdCallLibrary {
Mqrt INSTANCE = Native.load("mqrt", Mqrt.class);
int MQReceiveMessage(
long hSource, // INT_PTR
int dwTimeout, // DWORD
int dwAction, // DWORD
Pointer pMessageProps, // MQMSGPROPS* optional, in/out
Pointer lpOverlapped, // OVERLAPPED* optional, in/out
Callback fnReceiveCallback, // PMQRECEIVECALLBACK optional
Pointer hCursor, // HANDLE optional
Pointer pTransaction // ITransaction* optional
);
}@[Link("mqrt")]
lib Libmqrt
fun MQReceiveMessage = MQReceiveMessage(
hSource : LibC::SSizeT, # INT_PTR
dwTimeout : UInt32, # DWORD
dwAction : UInt32, # DWORD
pMessageProps : MQMSGPROPS*, # MQMSGPROPS* optional, in/out
lpOverlapped : OVERLAPPED*, # OVERLAPPED* optional, in/out
fnReceiveCallback : Void*, # PMQRECEIVECALLBACK optional
hCursor : Void*, # HANDLE optional
pTransaction : Void* # ITransaction* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MQReceiveMessageNative = Int32 Function(IntPtr, Uint32, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef MQReceiveMessageDart = int Function(int, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final MQReceiveMessage = DynamicLibrary.open('mqrt.dll')
.lookupFunction<MQReceiveMessageNative, MQReceiveMessageDart>('MQReceiveMessage');
// hSource : INT_PTR -> IntPtr
// dwTimeout : DWORD -> Uint32
// dwAction : DWORD -> Uint32
// pMessageProps : MQMSGPROPS* optional, in/out -> Pointer<Void>
// lpOverlapped : OVERLAPPED* optional, in/out -> Pointer<Void>
// fnReceiveCallback : PMQRECEIVECALLBACK optional -> Pointer<Void>
// hCursor : HANDLE optional -> Pointer<Void>
// pTransaction : ITransaction* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MQReceiveMessage(
hSource: NativeInt; // INT_PTR
dwTimeout: DWORD; // DWORD
dwAction: DWORD; // DWORD
pMessageProps: Pointer; // MQMSGPROPS* optional, in/out
lpOverlapped: Pointer; // OVERLAPPED* optional, in/out
fnReceiveCallback: Pointer; // PMQRECEIVECALLBACK optional
hCursor: THandle; // HANDLE optional
pTransaction: Pointer // ITransaction* optional
): Integer; stdcall;
external 'mqrt.dll' name 'MQReceiveMessage';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MQReceiveMessage"
c_MQReceiveMessage :: CIntPtr -> Word32 -> Word32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Int32
-- hSource : INT_PTR -> CIntPtr
-- dwTimeout : DWORD -> Word32
-- dwAction : DWORD -> Word32
-- pMessageProps : MQMSGPROPS* optional, in/out -> Ptr ()
-- lpOverlapped : OVERLAPPED* optional, in/out -> Ptr ()
-- fnReceiveCallback : PMQRECEIVECALLBACK optional -> Ptr ()
-- hCursor : HANDLE optional -> Ptr ()
-- pTransaction : ITransaction* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let mqreceivemessage =
foreign "MQReceiveMessage"
(intptr_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hSource : INT_PTR -> intptr_t *)
(* dwTimeout : DWORD -> uint32_t *)
(* dwAction : DWORD -> uint32_t *)
(* pMessageProps : MQMSGPROPS* optional, in/out -> (ptr void) *)
(* lpOverlapped : OVERLAPPED* optional, in/out -> (ptr void) *)
(* fnReceiveCallback : PMQRECEIVECALLBACK optional -> (ptr void) *)
(* hCursor : HANDLE optional -> (ptr void) *)
(* pTransaction : ITransaction* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mqrt (t "mqrt.dll"))
(cffi:use-foreign-library mqrt)
(cffi:defcfun ("MQReceiveMessage" mqreceive-message :convention :stdcall) :int32
(h-source :int64) ; INT_PTR
(dw-timeout :uint32) ; DWORD
(dw-action :uint32) ; DWORD
(p-message-props :pointer) ; MQMSGPROPS* optional, in/out
(lp-overlapped :pointer) ; OVERLAPPED* optional, in/out
(fn-receive-callback :pointer) ; PMQRECEIVECALLBACK optional
(h-cursor :pointer) ; HANDLE optional
(p-transaction :pointer)) ; ITransaction* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MQReceiveMessage = Win32::API::More->new('mqrt',
'int MQReceiveMessage(LPARAM hSource, DWORD dwTimeout, DWORD dwAction, LPVOID pMessageProps, LPVOID lpOverlapped, LPVOID fnReceiveCallback, HANDLE hCursor, LPVOID pTransaction)');
# my $ret = $MQReceiveMessage->Call($hSource, $dwTimeout, $dwAction, $pMessageProps, $lpOverlapped, $fnReceiveCallback, $hCursor, $pTransaction);
# hSource : INT_PTR -> LPARAM
# dwTimeout : DWORD -> DWORD
# dwAction : DWORD -> DWORD
# pMessageProps : MQMSGPROPS* optional, in/out -> LPVOID
# lpOverlapped : OVERLAPPED* optional, in/out -> LPVOID
# fnReceiveCallback : PMQRECEIVECALLBACK optional -> LPVOID
# hCursor : HANDLE optional -> HANDLE
# pTransaction : ITransaction* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。