We help IT Professionals succeed at work.

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

8,133 Views
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.
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
fridomCEO/Programmer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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?
fridomCEO/Programmer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
Hi, based on link provided
http://www.codeguru.com/cpp/com-tech/activex/article.php/c5547/

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 {
      importlib("stdole32.tlb");
      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
created
class CMiniDcom2 : public ITriple // similar way what is there for CMiniDcom

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

main()
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();
CoRegisterClassObject(CLSID_MiniDcom, pIFactory, CLSCTX_LOCAL_SERVER, REGCLS_SUSPENDED|REGCLS_MULTIPLEUSE, &dwRegister);

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?

Thanks.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.