Re: COM beginner - 2 apps using the same instance of a component.
From: xtreem (invalid_at_hotmail.com)
Date: 09/18/04
- Previous message: William McIlroy: "Looking for Document"
- Maybe in reply to: Eric: "COM beginner - 2 apps using the same instance of a component."
- Next in thread: Eric: "Re: COM beginner - 2 apps using the same instance of a component."
- Reply: Eric: "Re: COM beginner - 2 apps using the same instance of a component."
- Reply: Igor Tandetnik: "Re: COM beginner - 2 apps using the same instance of a component."
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 19 Sep 2004 00:10:15 +1000
"xtreem" <invalid@hotmail.com> wrote in message
news:414c01a8$0$19428$61c65585@uq-127creek-reader-01.brisbane.pipenetworks.com.au...
> "Igor Tandetnik" <itandetnik@mvps.org> wrote in message
> news:%23j62NPMnEHA.3172@TK2MSFTNGP10.phx.gbl...
>> "Eric" <eric_boissard@hotmail.com> wrote in message
>> news:d9a55bc6.0409170633.47637859@posting.google.com
>>> I am trying to learn COM at the moment. I have managed to write a
>>> simple COM component in a dll. I can create one instance of this
>>> component in a simple app. What I would like to do noe, is to create a
>>> second app that uses the same instance of this object.
>>
>> Bad idea. If you want that, you should have created an out-of-proc
>> component in the first place (the one implemented in an EXE rather than
>> a DLL).
>
> Id also like to do something similar. The reason I have originally made it
> an in-proc dll server is because that is how it is used most of the time,
> but I would like to expose it as well.
>
> It is a automation object in a .dll which is loaded by a host .exe as a
> plugin. I am using the automation object to control various aspects of the
> application, through scripts that run in-process and eventually by other
> processes which obtain this object.
>
> I realise I could make an out of proc server exe project and just make it
> into a .dll, but Id prefer to keep it how it is if possible.
>
> I would prefer not to touch the registry for this project, I had intended
> on just calling CoRegisterClass with a custom IClassFactory which just
> returns my object. External apps would get my object through 'GetObject'
> type of calls with the GUID, rather than 'CreateObject' with a prog id.
>
> Would this work ok? What are the significant differences between a .dll
> and .exe ATL project? Keeping in mind I will be avoiding registering stuff
> in the registry.
>
I managed to figure it out, the following two lines pretty did the trick,
plus putting DECLASE_CLASS_FACTORY_SINGLETON in the application object.
HRESULT hr = CoRegisterClassObject(CLSID_Application,
(IUnknown*)pApplication->GetUnknown(), CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE, &dwr);
hr = RegisterActiveObject(pApplication->GetUnknown(), CLSID_Application,
ACTIVEOBJECT_WEAK, &dwr2);
Its probably not perfect, but I'll fine tune it over time.
- Previous message: William McIlroy: "Looking for Document"
- Maybe in reply to: Eric: "COM beginner - 2 apps using the same instance of a component."
- Next in thread: Eric: "Re: COM beginner - 2 apps using the same instance of a component."
- Reply: Eric: "Re: COM beginner - 2 apps using the same instance of a component."
- Reply: Igor Tandetnik: "Re: COM beginner - 2 apps using the same instance of a component."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|