Skip to content

Instantly share code, notes, and snippets.

@wjx0912
Created March 24, 2018 07:34
Show Gist options
  • Save wjx0912/c2aff6fd2419d68f4ce3462a6737bb10 to your computer and use it in GitHub Desktop.
Save wjx0912/c2aff6fd2419d68f4ce3462a6737bb10 to your computer and use it in GitHub Desktop.
c++ message object management 2
// send
SendingMethod::SendMsgId( ... )
{
...
std::unique_ptr<MyParams> myParams( new MyParams(value1, value2, value3) );
if (PostThreadMessage(MSG_ID, 0, reinterpret_cast<LPARAM>(myParams.release())) {
myParams.release();    // is postmessage failed
}
...
}
// receive
ReceivingMethod::OnMsgId( WPARAM wParam, LPARAM lParam)
{
std::unique_ptr<MyParams> myParams( reinterpret_cast<MyParams*>(lParam) );
... // use object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment