Introduction

Using COM technology to pass simple data like long, int, etc is easy.
And what about structured data like C++ classes?

The most developers know the way to pass that.
This way is based on passing data using VARIANT as SAFEARRAY.
And what does VARIANT mean?

The VARIANT is perhaps the ultimate in general purpose functionality for passing data.
But its range of low-level features can be daunting. I did not find a suitable library for
the easy use of one in my projects.

To resolve this problem I built two classes to provide richer interfaces and easier semantics.
The first class called CDComObj. This class is responsible for Reading/Writing data into/from VARIANT.
The second class, CDcomObjArray, is responsible for passing collection of objects across DCOM.
By using both of these classes it is easy to implement any C++ class which has ability to pass itself across DCOM.

Notes

To avoid MFC at Server side I am using CString object from WTL V.3.1.
So, you should download one from Microsoft site.
In any case don't forget to setup path to this library in your Compiler: Tools/Options/Directories.

After establishing connection you can see list of connected users in any
Client

Start another one instance again and list of connected users will
grow

What's going on?

Under connection stage the client is sending to the server a C++ class CConnection.

If the server accepted this request it sends a collection of CConnection classes
to everything connected clients.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

very nice article Eugene (it's still alive) .
The sample project works excellent under VC++6.0 but I've converted (without changes) the project into .NET 7.1.
The code compiles and when I launch a client it will connect with the server however it does not get an event/update back, the client hangs (does not respond) .

Although when I launch a (old) 6.0 client with the (new) .NET server everything works fine. So the .NET server seems not to be the problem.

How can I get the client working properly under .NET?
Probably some simple setting (I'm newbie in DCOM)???

Hello,
Isn't there any standard way to stream a COM object through a DCOM connection? I suppose that microsoft should have thought at this. Maybe with the new ATL 7.0 version?
Besides, in ATL 7.0 you have the possibility to export some structs? whouldn't it be simpler, than using VARIANT?
I have tried this but it failed if I used a pointer to a struct in an event interface. when rising the event the result code was 0xc0000005 (unknown error).
Have anyone succeded?
Thanks.

I believe the answer is yes there is, at least, if you are asking if there is a standard way of passing a FIXED structure. It is documented in the "User-Defined Data Types" section of MSDN. a little synopsis is below.

if you create a structure with its own GUID in the library section of the IDL, then use the IRecordInfo interface. The MS documentatation about user defined types is still slim, but to summerise

Which publishes the type - so you can now use the structure in the interfaces to your COM object (so as long as you use types recognised by MIDL). Your client either loads the type library or imports it, to fetch it use something like:

When you do CoCreateInstanceEx without DECLARE_CLASSFACTORY_SINGLETON
each client will create a separate instance of a server.
When you declare DECLARE_CLASSFACTORY_SINGLETON the CoCreateInstanceEx will create just one instance of a server. And all clients will connect to the single server.

I connect myself already like that and I have several instance of my class.
The trouble is after having call to the function "connect", the server calls the destructor. Thus I lose the information.
"my class is connected towards a serial port. »

In Sink event thread you calling member function in another thread. Program will fail when trying to access UI controls in Dialog class.
The better way to notify UI from another tread is signaling with WinAPI PostMessage or PostThreadMessage call

The number of connections a connection point supports is TOTALLY DEPENDENT on the implementation. It might be 1, it might 100, it might be 1000000.

However, the error you are getting is a server fault error. It means that the server threw an exception that the RPC proxy code caught.

Tim Smith

I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?