C# 发送方
//引入 Interop 库 using System.Runtime.InteropServices; //定义 SendMessage API [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam); //定义发送消息的常量 static uint WM_USER = 0x0400; //在需要发送消息的位置调用 SendMessage API SendMessage(hWnd, WM_USER, IntPtr.Zero, IntPtr.Zero); //如果是字符串 SendMessage(hwnd, WM_USER, Marshal.StringToHGlobalAnsi(""), (IntPtr)0);
C++接收方
//如果是接收字符串 LPCSTR str = reinterpret_cast<LPCSTR>(wParam); CString cstr = CString(str); //如果是int类型 int code = wParam
hwnd为C++指定窗口
标签:IntPtr,C#,WM,C++,SendMessage,USER,消息传递 From: https://www.cnblogs.com/INSTANTMOC/p/17468443.html