We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Send object using SendMessage in MFC (delete)

thready
thready asked
on
Medium Priority
662 Views
Last Modified: 2012-05-11
Hi Experts,

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!

Thanks,
Mike
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
>> I don't want memory leaks - how do I know if p was deleted on the other side?
If you are responsible for writing the other side, then you are responsible for new and corresponding delete. If you are not responsible for the other side, then when they complain about "your" program causing their program to crash, you have to go calmly into finger-pointing mode, and either help them or prove via TCP dumps that you are not causing "their" problem.

Author

Commented:
of course - I don't need to call new in the first place.  I was worried that the data would go out of scope, but it's copied when sent by value ( as long as the objects are of known simple types).  Thanks!
CERTIFIED EXPERT

Commented:
Glad to be of assistance. It always helps to have an extra set of eyes.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.