FireForce
FireForce

Reputation: 23

MFC Send the object in message

Can i send the message with object? Something like:

myClass *myObj = new myClass();
pDlg->SendMessage(MyEvent, NULL, (LPARAM)&myObj); // Sends without any errors
...
afx_msg LRESULT MyApp::GetEvent(WPARAM wParam, LPARAM lParam)
{
    myClass *zxc = new myClass();
    zxc = lParam; // Something like this... but doesn't work
}

Upvotes: 1

Views: 1310

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477040

Just cast the pointer there-and-back as appropriate:

Sender:

pDlg->SendMessage(MyEvent, NULL, reinterpret_cast<LPARAM>(&myObj));

Receiver:

afx_msg LRESULT MyApp::GetEvent(WPARAM wParam, LPARAM lParam)
{
    myClass * zxc = reinterpret_cast<myClass*>(lParam);
    // ...
}

Upvotes: 2

Related Questions