开发者

Does an ATL COM Object Have a Message Pump?

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 m开发者_如何学Goessages 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜