Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › DispatchMessageW

DispatchMessageW

関数
メッセージを対応するウィンドウプロシージャへ送出する(Unicode)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

LRESULT DispatchMessageW(
    const MSG* lpMsg
);

パラメーター

名前方向
lpMsgMSG*in

戻り値の型: LRESULT

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

LRESULT DispatchMessageW(
    const MSG* lpMsg
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr DispatchMessageW(
    IntPtr lpMsg   // MSG*
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DispatchMessageW(
    lpMsg As IntPtr   ' MSG*
) As IntPtr
End Function
' lpMsg : MSG*
Declare PtrSafe Function DispatchMessageW Lib "user32" ( _
    ByVal lpMsg As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DispatchMessageW = ctypes.windll.user32.DispatchMessageW
DispatchMessageW.restype = ctypes.c_ssize_t
DispatchMessageW.argtypes = [
    ctypes.c_void_p,  # lpMsg : MSG*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
DispatchMessageW = Fiddle::Function.new(
  lib['DispatchMessageW'],
  [
    Fiddle::TYPE_VOIDP,  # lpMsg : MSG*
  ],
  Fiddle::TYPE_INTPTR_T)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn DispatchMessageW(
        lpMsg: *const MSG  // MSG*
    ) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr DispatchMessageW(IntPtr lpMsg);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_DispatchMessageW' -Namespace Win32 -PassThru
# $api::DispatchMessageW(lpMsg)
#uselib "USER32.dll"
#func global DispatchMessageW "DispatchMessageW" wptr
; DispatchMessageW varptr(lpMsg)   ; 戻り値は stat
; lpMsg : MSG* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USER32.dll"
#cfunc global DispatchMessageW "DispatchMessageW" var
; res = DispatchMessageW(lpMsg)
; lpMsg : MSG* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; LRESULT DispatchMessageW(MSG* lpMsg)
#uselib "USER32.dll"
#cfunc global DispatchMessageW "DispatchMessageW" var
; res = DispatchMessageW(lpMsg)
; lpMsg : MSG* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procDispatchMessageW = user32.NewProc("DispatchMessageW")
)

// lpMsg (MSG*)
r1, _, err := procDispatchMessageW.Call(
	uintptr(lpMsg),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LRESULT
function DispatchMessageW(
  lpMsg: Pointer   // MSG*
): NativeInt; stdcall;
  external 'USER32.dll' name 'DispatchMessageW';
result := DllCall("USER32\DispatchMessageW"
    , "Ptr", lpMsg   ; MSG*
    , "Ptr")   ; return: LRESULT
●DispatchMessageW(lpMsg) = DLL("USER32.dll", "int DispatchMessageW(void*)")
# 呼び出し: DispatchMessageW(lpMsg)
# lpMsg : MSG* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。