YeP
YeP

Reputation: 211

SendMessage to 64bit application is not working

I use the following function to send message to application. It seems to work find for a 32bit application but doesn't work for a 64bit application (the 64bit application does not seem to get any message). What is wrong and how can I fix it? Thank you.

void MyTest::SendCmd(HWND hwnd, QString cmd)
{
COPYDATASTRUCT data;
data.dwData = FIXHEADER;
data.cbData = cmd.size()+1;
data.lpData = cmd.toLocal8Bit().data();

LPARAM lpdwResult;
LRESULT err = SendMessageTimeout(hwnd, WM_COPYDATA, 0, (LPARAM)&data, SMTO_ABORTIFHUNG, 2000, &lpdwResult); 
}
//FIXHEADER is a fixed hex value that the application checks against to make sure the message is sent intentional for it.

Upvotes: 0

Views: 3150

Answers (1)

Behnam Azizi
Behnam Azizi

Reputation: 11

You need to compile your application in 64-bit mode otherwise this cannot work and 64-bit handles are truncated making them invalid.

Some reading for you: https://learn.microsoft.com/en-us/windows/desktop/winauto/32-bit-and-64-bit-interoperability

Upvotes: 1

Related Questions