C++ out-of-process COM server / client example

Posted on 2007-09-28
Last Modified: 2013-11-25
I need a very basic source code example for an out-of-process COM server and client on Visual Studio 2005. Bo the client & server should be written in C++. can somebody point me to the right place.
Question by:swsbuyer
    LVL 12

    Accepted Solution

    LVL 24

    Assisted Solution

    There are still some good book out there for that:
    Essential COM
    COM and ATL (CD with exe-server)
    .NET and COM (very actual and 2000 pages of info ;-)
    Understanding and Programming COM


    Author Comment

    I tried the solution by OnegaZhang. This works correctly with VC6.0. Then I converted it with VS 2005, and got a compiler error

    "server_p.c: fatal error C1189: #error :  You need a Windows 2000 or later to run this stub because it uses these features".

     I added "_WIN32_WINNT=0x0500" to the preprocessor definitions. But then I get several link warnings:

    1>.\Proxy.def : warning LNK4222: exported symbol 'DllGetClassObject' should not be assigned an ordinal
    1>.\Proxy.def : warning LNK4222: exported symbol 'DllCanUnloadNow' should not be assigned an ordinal
    1>.\Proxy.def : warning LNK4222: exported symbol 'DllRegisterServer' should not be assigned an ordinal
    1>.\Proxy.def : warning LNK4222: exported symbol 'DllUnregisterServer' should not be assigned an ordinal

    Is there something else I need to do?
    LVL 24

    Assisted Solution

    You probably have to declare this functions as
    either as
    DllCanUnoadNow @1 PRIVATE
    or simply drop the @1 completly
    as seen above this things should not show up in the "public" interface.


    Expert Comment

    Hi, based on link provided

    I built COM server in similar manner. I able to access via client properly.

    When I am trying to extend the COM server interfaces I am getting failure when doing CoCreateInstanceEx(E_NO_INTERFACE)

    .idl --- code
    [ object, uuid(725AB476-9A20-401e-B1AA-A272288A90E6) ]
    interface ITriple : IDispatch {
          HRESULT Triple(int x, [out, retval] int* retval); }

    library Server {
          interface IDouble;
          [ uuid(10000002-0000-0000-0000-000000000001) ]
          coclass MiniDcom      {
                interface IDouble;      }

          interface ITriple;
          [ uuid(98BB1009-F869-408b-9287-70AB11720913) ]
          coclass MiniDcom2       {
                interface ITriple;       }

    Server.cpp /// code
    class CMiniDcom2 : public ITriple // similar way what is there for CMiniDcom

    class CFactory2 : public IClassFactory  // similar way as per CFactory

    RegisterServer("Server.exe", CLSID_MiniDcom, "MiniDcom Sample", "Component.MiniDcom", "Component.MiniDcom.1", NULL);
    RegisterServer("Server.exe", CLSID_MiniDcom2, "MiniDcom Sample2", "Component.MiniDcom2", "Component.MiniDcom2.1", NULL);

    IClassFactory *pIFactory = new CFactory();

    IClassFactory *pIFactory2 = new CFactory2();
    CoRegisterClassObject(CLSID_MiniDcom2, pIFactory2, CLSCTX_LOCAL_SERVER, REGCLS_SUSPENDED|REGCLS_MULTIPLEUSE, &dwRegister2);

    //// Client.cpp --- Inside Client code

    I am first calling CoCreateInstanceEx(CLSID_MiniDcom) -- this pass
    then calling
    hr = CoCreateInstanceEx(
                CLSID_MiniDcom2, NULL, CLSCTX_REMOTE_SERVER, &si, 1, rgmqi);
    I am here getting E_NO_INTERFACE failure. !!!

    If I call only CoCreateInstanceEx(CLSID_MiniDcom2) this works properly.
    things doesn't work if I want to create both CLSID.

    What could be worng here ? can someone pl. provide me correct approach to implement multiple CoCreateInstance for different CLSID?



    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now