How to marshall COM object on the server side in visual c++?
I have a out-of-process COM server with an ATL Simple Object which creates another th开发者_如何学Pythonread. The new thread will need to make calls to ATL Simple object. Since ATL Simple Object and new thread are created different apartments, ATL Simple Object needs to be marshalled in the new thread, otherwise error 0x8001010e will be generated.
How do I marshall COM Object on the server side or Am I missing something?
Many thanks.
My apologies if this answer is way off, but I'm unclear on the specifics of what you're trying to accomplish.
I think that this is a design problem, rather than an implementation one. Why isn't the Simple Object created in/by the new thread?
If you're looking to communicate across a thread boundary, I suggest using one of the widely-accepted patterns (Mailbox, Event) to signal the new thread's dispatcher to perform operations the next time it is available.
Could you elaborate on the specifics of the issue? I'd love to help as this seems right up my alley...
Take a look at CoMarshalInterThreadInterfaceInStream. If you google this you'll find some examples how to use it.
Hope that helps.
If you're familiar with ATL - I suggest you to use CComGITPtr. It's a smart pointer which can publish your interfaces in Global Interface table and you can later reach them from other apartments. But GIT is global in terms of one process.
Another one point - do you implement proxy stub for your ATL Simple Object? If you don't build proxy stub, then your ATL Simple Object should expose and implement IDispatch. With its help the proxy will be created automatically.
精彩评论