Does anyone have any idea why this might happen?
Many thanks.
Alex Lamaison
Vista 32-bit/MSVC8
My guess is, you start a thread, create the object on it, then allow that thread to terminate. This kills the apartment, and forces COM to release the object prematurely. Any proxies to it would then return RPC_E_DISCONNECTED on any call.
--
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
> Alexander Lamaison wrote:
>> I'm using the RunningObjectTable to store an object (in a seperate in-proc
>> server) that is used by several threads. The first thread creates and
>> registers the object in the ROT. When the other threads try to retrieve
>> the object via GetObject() it returns RPC_E_DISCONNECTED.
>
> My guess is, you start a thread, create the object on it, then allow that thread to terminate. This kills the apartment, and forces COM to release the object prematurely. Any proxies to it would then return RPC_E_DISCONNECTED on any call.
Ouch. Yes, that's exactly what I'm doing.
Is there a way to make an object survive the destruction of the thread that
created it? At the moment this is just a mockup for my unit tests but the
real situation I'm trying to model is where Windows Explorer calls my code
from several seperate threads and I cache an object in the ROT between
calls (this was failing).
Many thanks.
Alex Lamaison
Thread: yes; apartment: no. For STA apartments, the two are one and the same, so the thread that created the object must remain alive (and run a message pump). For MTA apartments, threads may come and go, but at least one thread must be running in the MTA apartment at all times to keep it alive.
> At the moment this is just a mockup for my unit tests but the
> real situation I'm trying to model is where Windows Explorer calls my code
> from several seperate threads and I cache an object in the ROT between
> calls (this was failing).
See if SHLoadInProc helps. You may also want to ask in microsoft.public.platformsdk.shell.
> Alexander Lamaison wrote:
>
>> At the moment this is just a mockup for my unit tests but the
>> real situation I'm trying to model is where Windows Explorer calls my code
>> from several seperate threads and I cache an object in the ROT between
>> calls (this was failing).
>
> See if SHLoadInProc helps.
Unfortunately this function is disabled in Vista which, coincidentally, is
the first version of Windows that my code broke on.
> You may also want to ask in microsoft.public.platformsdk.shell.
Will do. Thanks Igor :)