|
Prev: asynchronous and synchronous call between apartments
Next: [ANN]: AutoFlowchart v2.4, the Professional sourcecode flowcharting tool.
From: George on 5 Apr 2008 03:36 Hello everyone, When we have cross-apartment call (inside one process) from ... to ..., 1. STA --> MTA; 2. MTA --> STA. In both cases we must use either GIT (global interface table) or CoMarshalInterThreadInterfaceInStream? If call method on destination apartment through interface pointer of component of destination apartment directly is violation (bypass the above two methods)? (for example, sharing raw interface pointer directly in global variable and call methods on interface pointer directly) thanks in advance, George
From: Alex Blekhman on 5 Apr 2008 04:58 "George" wrote: > When we have cross-apartment call (inside one process) from ... > to ..., > > 1. STA --> MTA; > 2. MTA --> STA. > > In both cases we must use either GIT (global interface table) or > CoMarshalInterThreadInterfaceInStream? Yes. An interface pointer must always be marshalled across appartments. > If call method on destination apartment through interface > pointer of > component of destination apartment directly is violation (bypass > the above > two methods)? > > (for example, sharing raw interface pointer directly in global > variable and > call methods on interface pointer directly) Yes, it is a violation of COM rules. You'll get an error if you do such call. Alex
From: Igor Tandetnik on 5 Apr 2008 11:17 "Alex Blekhman" <tkfx.REMOVE(a)yahoo.com> wrote in message news:O1M6DtvlIHA.1052(a)TK2MSFTNGP05.phx.gbl > "George" wrote: >> If call method on destination apartment through interface >> pointer of >> component of destination apartment directly is violation (bypass >> the above >> two methods)? >> >> (for example, sharing raw interface pointer directly in global >> variable and >> call methods on interface pointer directly) > > Yes, it is a violation of COM rules. You'll get an error if you do > such call. Unfortunately, the problem is that you _won't_ get an immediate error in this case. It's a direct call, so COM runtime is out of the picture and doesn't have a chance to intervene. You are calling a component on a thread it was not designed to be called on - which may appear to work sometimes, and fail other times. For example, an STA component might end up being called simultaneously on two threads, thus creating a race condition it is not prepared to handle. You may be thinking about a situation where a COM proxy pointer is being passed across apartments without marshalling. A proxy does detect that it's being called on a wrong thread, and reports an error. But a direct COM pointer typically doesn't. -- 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
From: Alex Blekhman on 5 Apr 2008 13:15 "Igor Tandetnik" wrote: > You may be thinking about a situation where a COM proxy pointer > is being passed across apartments without marshalling. A proxy > does detect that it's being called on a wrong thread, and > reports an error. But a direct COM pointer typically doesn't. Thanks Igor, it's a good point. Yes, usually I call other COM objects that live in different appartment, so I get RPC_E_WRONG_THREAD consistently. Alex
From: George on 6 Apr 2008 21:39
Thanks Igor, I assume all cross-apartment call -- including the ones which I do not mention in my original post (MTA --> MTA, STA --> STA) -- should use the two methods (either GIT (global interface table) or CoMarshalInterThreadInterfaceInStream) I posted in the original post, or using the proxy pointer, if using direct pointer call, it should be either compile or expected behavior during runtime. Right? regards, George |