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

RegisterWindowMessageW

関数
アプリ間で一意なウィンドウメッセージを登録する(Unicode)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

DWORD RegisterWindowMessageW(
    LPCWSTR lpString
);

パラメーター

名前方向
lpStringLPCWSTRin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD RegisterWindowMessageW(
    LPCWSTR lpString
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint RegisterWindowMessageW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpString   // LPCWSTR
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RegisterWindowMessageW(
    <MarshalAs(UnmanagedType.LPWStr)> lpString As String   ' LPCWSTR
) As UInteger
End Function
' lpString : LPCWSTR
Declare PtrSafe Function RegisterWindowMessageW Lib "user32" ( _
    ByVal lpString As LongPtr) As Long
' 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

RegisterWindowMessageW = ctypes.windll.user32.RegisterWindowMessageW
RegisterWindowMessageW.restype = wintypes.DWORD
RegisterWindowMessageW.argtypes = [
    wintypes.LPCWSTR,  # lpString : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
RegisterWindowMessageW = Fiddle::Function.new(
  lib['RegisterWindowMessageW'],
  [
    Fiddle::TYPE_VOIDP,  # lpString : LPCWSTR
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn RegisterWindowMessageW(
        lpString: *const u16  // LPCWSTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern uint RegisterWindowMessageW([MarshalAs(UnmanagedType.LPWStr)] string lpString);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_RegisterWindowMessageW' -Namespace Win32 -PassThru
# $api::RegisterWindowMessageW(lpString)
#uselib "USER32.dll"
#func global RegisterWindowMessageW "RegisterWindowMessageW" wptr
; RegisterWindowMessageW lpString   ; 戻り値は stat
; lpString : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global RegisterWindowMessageW "RegisterWindowMessageW" wstr
; res = RegisterWindowMessageW(lpString)
; lpString : LPCWSTR -> "wstr"
; DWORD RegisterWindowMessageW(LPCWSTR lpString)
#uselib "USER32.dll"
#cfunc global RegisterWindowMessageW "RegisterWindowMessageW" wstr
; res = RegisterWindowMessageW(lpString)
; lpString : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procRegisterWindowMessageW = user32.NewProc("RegisterWindowMessageW")
)

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