Re: marshall interface needed?
"George" <George@discussions.microsoft.com> wrote in message
news:DBE107C3-4F38-431B-B92A-668214B9583F@microsoft.com
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.
In your sample above, when call to B will fail with
RPC_E_WRONG_THREAD fails in STA, it is because STA is using the proxy
pointer of B for MTA A, other than proxy for STA, right?
Right.
The solution is, either marshall interface from B to STA, or marshall
interface (to B) from MTA A to STA? Both are correct?
You, as a client of A, don't have access to B pointer, and in fact don't
need to know nor care that A uses B at all. That is A's implementation
detail. The solution is not to break COM rules in the first place, and
properly marshal A's pointer.
Again, the claim that you can freely pass a direct pointer to an MTA
object between apartments is wrong. Like any other COM pointer, it needs
to be marshalled.
--
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