How to send struct or pointer using SendMessage or PostMessage function?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is simple example:
Don’t ever try to do it between processes.Study IPC basics first.
Don’t forget to release pointer to struct once not needed using
delete.
UPDATE
As Remy Lebeau mentioned in comment, you can also allocate struct on stack instead on heap using new/malloc, because SendMessage block thread until it’s processed in WndProc.This does not apply to PostMessage which add message to window’s message queue and return immediately, so it requires heap block.
However, if you plan to pass more complex data struct I recommend heap allocation instead of stack.