Re: COM beginner - 2 apps using the same instance of a component.

From: xtreem (invalid_at_hotmail.com)
Date: 09/18/04

  • Next message: Hawk: "Re: Did MS changed some interface methods in Outlook View Control"
    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.


  • Next message: Hawk: "Re: Did MS changed some interface methods in Outlook View Control"

    Relevant Pages

    • Re: secure32.exe
      ... > kind of search could be used - I tried to search files that had the text ... Exe can register this dll as Winlogon ... or as extension in AppInit_Dlls registry key - this allows dll to ...
      (microsoft.public.security.virus)
    • Re: Using same interfaces for in-proc vs. out-proc
      ... I forgot to mention that when I compile the DLL after removing the TYPELIB ... and REGISTRY entries in the RC file I still get this message: ... for the COM part is in the same project as the rest of the EXE code. ...
      (microsoft.public.vc.atl)
    • Re: Transferring programmes from one partition to another
      ... the same dll location. ... If the exe file is moved, the association is broken and is not ... The dll may look to the registry but since the exe and ... of registry entries involed, you could in theory anyway, update the registry ...
      (microsoft.public.windowsxp.general)
    • Re: Accessing a DLL without registering it
      ... You could simply try to create an object from one of the classes in the dll, ... You can directly check for the CLSID in the registry. ... If the dll is in the same directory as the exe, ... The way the accounting package works is, ...
      (microsoft.public.vb.general.discussion)
    • Problem with performance of IDE devices
      ... index 0, dll tcpstk.dll, context 0x3f8a5c9 ... 0x801abbe8: FSREG: Mounted ROM portion of boot registry ... 0x8014abcc: FSREG: Invalid HKEY 0x00000000 ...
      (microsoft.public.windowsce.platbuilder)

    Loading