I was wondering what's the difference between calling SendMessage (which blocks) and calling PostMessage in conjunction with WaitForSingleObject.
Thoughts?
C++ – SendMessage vs PostMessage + WaitForSingleObject
cpostmessagesendmessagewaitforsingleobjectwinapi
Related Topic
- C++ – The Definitive C++ Book Guide and List
- C++ – Difference between private, public, and protected inheritance
- C++ – the copy-and-swap idiom
- C++ – What are the basic rules and idioms for operator overloading
- C++ – Why are elementwise additions much faster in separate loops than in a combined loop
- C++ – Image Processing: Algorithm Improvement for ‘Coca-Cola Can’ Recognition
- C++ – Difference between `constexpr` and `const`
Best Answer
SendMessage()
may be denied, if you call it from within the context of a COM call, where the COM object lives in an STA (calls are dispatched through the message pump).PostMessage()
is not restricted to adhere to COM apartment rules.Also,
PostMessage()
puts the message on the end of the window's message queue.SendMessage()
bypasses the queue. You can find a lengthier discussion on message queues on Raymond Chen's blog The Old New Thing.My point is that there is more to the difference between
SendMessage()
andPostMessage()
than meets the eye. I really recommend going through Raymond's blog, as he has covered many gotchas over the years.