[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-09-28
5
Medium Priority
?
7,341 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.
0
Comment
Question by:swsbuyer
5 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 1200 total points
ID: 19982647
0
 
LVL 24

Assisted Solution

by:fridom
fridom earned 300 total points
ID: 19984185
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

Regards
Friedrich
0
 

Author Comment

by:swsbuyer
ID: 19990764
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?
0
 
LVL 24

Assisted Solution

by:fridom
fridom earned 300 total points
ID: 19991587
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.

Regards
Friedrich
0
 

Expert Comment

by:swift04
ID: 35381378
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.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 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