Send object using SendMessage in MFC (delete)
Posted on 2011-04-26
I'd like to send a string or two and an integer using SendMessage or PostMessage. Let's say I have an object:
pair<string, int> * p = new pair<string, int>();
p->first = "this";
p->second = 5;
PostMessage(WM_MY_MESSAGE, 0, (LPARAM) p );
I don't want memory leaks - how do I know if p was deleted on the other side? i.e., I have to be sure someone handled the message and deleted p. Simple enough, but I guess there's no way to delete it from the message sender since PostMessage will only be handled long after the calling function has already returned right?
Just thinking out loud and playing devil's advocate.... Let me know your thoughts please!