views:

295

answers:

3

I have a out-of-process COM server with an ATL Simple Object which creates another thread. 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.

A: 

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...

Josh
On server side, when ATL Simple Object is created on client request , the new thread is also created to launch a GUI Wxwidget application. The creation of the wxWidget app can be inside the constructor of the ATL Simple Object.WxWidget app will fire events through ATL Simple Object. This means wxApp will need to call methods of ATL Simple Object.Since WxApp and ATL Simple object are not on the same thread,COM issues an error of 0x8001010e.
dos
So is this model correct?1) Client sends request to server2) Server spawns two objects; COM Object (ATL Simple Object) and WxApp (New Thread) - Purpose of COM Object is to "manage" the WxApp3) Whenenver COM Object calls on ATL, get thread-boundary assertionIt seems as though this is a design issue. Please refer to this article for the mechanics of multi-threaded COM and events:http://msdn.microsoft.com/en-us/library/ms693421%28VS.85%29.aspxThe server should provide an interface which fires events to the relevant WxApp threads. These threads then operate on the relevant events.
Josh
Comments are poor (no formatting). I'll elaborate in a full answer once I clarify what you need. I'm feeling rather slow today (sorry)!
Josh
I am not sure it is a design issue.In step 3, upon receiving use's click via, wxApp will catch user events and fire COM event to the out-of-process client via ATL Object.Using ATL Object in wxApp's thread is the issue.I have tried MTA, i.e CSimpleObject : public CComObjectRootEx<CComSingleThreadModel>and defining _ATL_FREE_THREADED in the stdafx.hand still getting the same error.
dos
I meant to write class ATL_NO_VTABLE CSimpleObject : public CComObjectRootEx<CComMultiThreadModel>, ...
dos
A: 

Take a look at CoMarshalInterThreadInterfaceInStream. If you google this you'll find some examples how to use it.

Hope that helps.

Stephen Nutt
A: 

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.

Anatoliy