Re: marshall interface needed?
"George" <George@discussions.microsoft.com> wrote in message
news:80D6A586-732A-4EBB-9B79-0CF503943A56@microsoft.com
2. using raw interface pointer of MTA component directly, because some
document mentioned MTA component could be touched by any threads, not
limited to MTA threads which create the component.
No, this is illegal, and can lead to problems. For example, imagine an
MTA component (let's call it A) that itself uses another component
(named B), implemented in an out-of-proc server. So A holds a proxy to
B, marshalled for MTA. When you call a method on A, it does some work
and then calls a method on B. If A is called on an MTA thread (as it
should), everything works. But if you improperly transfer A's pointer to
STA and call it there, its call to B will fail with RPC_E_WRONG_THREAD
error returned by the proxy.
Or, a method of an MTA component may simply run for a long time without
processing messages. That's fine on an MTA thread, but if done on STA
thread, it may cause other applications (such as Explorer) to freeze.
A component can declare that it supports being called from any thread
(either STA or MTA) by registering as Both-threaded and aggregating
free-threaded marshaler (FTM) - see CoCreateFreeThreadedMarshaler. I
believe "ATL Internals" talks about it somewhere. If you know a
particular component implements FTM, then you can pass its pointer
freely between threads. Or, you can continue to properly marshal it -
FTM ensures that the outcome of the marshalling process is actually a
direct pointer, not a proxy pointer.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925