1

我们的 C++ 应用程序发送 WM_COPYDATA 消息:

typedef struct tagNotificationStruct {
    char msg[255];
} NotificationStruct;

void __stdcall LogMessageWrite()
{
    const char* pszMessage = "Test 1 2 3";

    NotificationStruct notification;
    strcpy(notification.msg, pszMessage);

    COPYDATASTRUCT copyDataStruct;
    copyDataStruct.dwData = 73; // random identification number
    copyDataStruct.cbData = sizeof(NotificationStruct);
    copyDataStruct.lpData = &notification;

    string text = "my window title";
    wchar_t wtext[15];
    mbstowcs(wtext, text.c_str(), text.length());
    LPWSTR ptr = wtext;
    HWND hwDispatch = FindWindow(NULL, ptr);

    if (hwDispatch != NULL) {
        SendMessage(hwDispatch, WM_COPYDATA, NULL, (LPARAM)(LPVOID)& copyDataStruct);
    }
}

在我们的 Electron 应用程序中,我们在 JavaScript 中侦听 WM_COPYDATA 消息:

browserWindow.hookWindowMessage(0x4A /* = WM_COPYDATA */, (wParam, lParam) => {
                console.log('wParam = ', wParam);
                console.log('lParam = ', lParam);
            });

我们收到消息,它给出了这个控制台输出:

wParam =  <Buffer@0x0000018C305F7160 00 00 00 00 00 00 00 00>
lParam =  <Buffer@0x0000018C305F6EC0 a0 f2 cf 42 8a 00 00 00>

我们如何在 JavaScript 中解释它,以便我们可以读取从 C++ 程序发送的字符串?

4

0 回答 0