WinAPI, sending / sending messages with 64-bit values ​​(wParam, lParam)

I encoded a program that uses MFC and therefore WinAPI functions like PostMessage. This is basically just one Window-thread and network-client-thread. I created my own post and it works great. To explain the program a bit:
I wrote a client that receives messages over the network, decodes them, and then must send messages to a window that displays message values. It all works - with 32-bit values. This, of course, incorrectly uses the PostMessage function, because lParam and wParam are pointers in normal mode. But I can’t only use pointers, because my client application and my Window application are two different threads, and the values ​​in the client application are deleted as soon as possible. (The client needs to call a circular request from the server)

#define DEVICE_INFO_DATETIME 70000
long long date;
date = (value->serverTimestamp);
PostMessage(getWindowHandle(), WM_NEW_DATA, date, DEVICE_INFO_DATETIME);

Thing - I get timestamps and other data encoded as 64 bits. And wparam and lparam are only 32 bits, so it always cuts my values. Well, I can compile it in 64-bit, then 64-bit values ​​are used, but this is incompatible with 32-bit systems (right?), Not what I want. The workaround for this type of code is to set a temporary 64-bit value or, possibly, an array of 64-bit values ​​as a global variable, but I do not want to save them all in a separate value relative to memory. The easiest way is to be the best solution.

Do you have any idea what I can do here?

+4
source share
1 answer

DEVICE_INFO_DATETIME WPARAM, LPARAM. SendMessage, .

long long date = 123;
SendMessage(getWindowHandle(), WM_NEW_DATA, DEVICE_INFO_DATETIME, (LPARAM)&date);

, WM_NEW_DATA , DEVICE_INFO_DATETIME , 70000.

#define WM_NEW_DATA WM_APP + 1
#define DEVICE_INFO_DATETIME 1


long long , PostMessage

#define WM_NEW_DATA2 WM_APP + 2

long long date = ...
int hi = date >> 32;
int lo = (int)date;
PostMessage(hwnd, WM_NEW_DATA2, (WPARAM)hi, (LPARAM)lo);

:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    if (msg == WM_NEW_DATA2)
    {
        long long date = ((long long)wParam << 32) + lParam;
    }
}



PostMessage: , ( malloc free)
//call:
long long *date = new long long;
PostMessage(hwnd, WM_APP + 3, DEVICE_INFO_DATETIME, (LPARAM)date);

//receive:
if (msg == WM_APP + 3)
{
    long long *date = (long long*)lParam;
    if (!date) return 0; //insufficient error check!
    delete date;//delete pointer when finished
}

. , PostMessage(hwnd, WM_APP + 3, DEVICE_INFO_DATETIME, 1);, . , LPARAM ( )

+5

Source: https://habr.com/ru/post/1623278/


All Articles