Question

If you create a new ATL project and add a simple COM object to it (note: an object and not a control) that uses the Apartment threading model, will there be a message pump running under the hood? I want to create a hidden window that is a member of my COM object class but I'm not sure if any messages will actually be delivered to it or not. Is this handled behind the scenes or does it matter what sort of application is actually creating the COM object?

Was it helpful?

Solution

No, an ATL COM object does not implement a message pump by default. Your code must explicitly use on via a normal Windowing library or explicit message pump implementation.

OTHER TIPS

COM uses a message pump under the hood for communicating with your COM object when necessary, if your COM object lives in an appartment. That's how methods are safely called on your object (by being serialized by the message queue) when called by an object in another appartment (STA or the MTA).

You can't get at the message pump - COM puts it together for you only when its needed. You'll notice when debugging that you call methods on your object directly - you're not jumping through a message pump. You would be, of course, if you were putting together multiple objects that live in different appartments.

If you need a window, you can create one using standard methods. ATL provides simple windows classes such as CWindow and CWindowImpl which can make this easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top