Click here to Skip to main content
13,296,407 members (50,728 online)
Click here to Skip to main content
Add your own
alternative version


51 bookmarked
Posted 6 Aug 2000

DCOM D-Mystified: A DCOM Tutorial, Step 5

, 11 Aug 2000
Rate this:
Please Sign up or sign in to vote.
We look at connection points and set up the server's end of one. We'll also finish implementing our SayHello() method.


Welcome to Step 5 of our DCOM tutorial. In this series, I will strip the mystique, the headache, and confusion from DCOM by giving you a comprehensive tutorial with a straightforward example. OK, no promises -- but I will give it a good try.

If you want to follow along with this tutorial and add code and use the Visual C++ Wizards as we go along, that's great. In fact, I very very highly recommend that, because otherwise this tutorial is a big waste of electronic ink (?). However, I follow along exactly with the tutorial myself, as I write it, and develop the code and use the Visual C++ wizards just as I say you should. The screenshots, in fact, are from my development of the files for each step! To download this already-developed code to compare with your own, simply click the 'Download the Step n Files - n KB" links at the top of each step. There's also an archive of the files for all the steps at the Questions and Answers page for this tutorial. I still recommend that you follow along with us as we go; this way, you can learn while you code. If you ever have problems along the way with this tutorial, feel free to:

Connection Points Demystified

Before we plunge in with Step 5 of our tutorial, let's just take a moment for me to rip the shrouds of mystery off of Connection Points. Figure 1 below shows a generic scenario which is true for COM, DCOM, and even function call backs, for goodness' sake.

A source and a sink.
Figure 1. A source and a sink.

This involves two objects, a "source" and a "sink". Think of the "source" like the water faucet of the kitchen sink at home. You turn a handle, and stuff comes out of it (hopefully water). Where does it go? If nothing's backed up, this water flows down into the bottom and goes into the drain (which can be thought of as the "sink"). OK, so things flow from the source, to the sink. In the kitchen sink analogy above, this is water. However, I've never seen a computer network system run with water flowing across the wires, so obviously something else is at work in DCOM.

In DCOM, there is a "client," somewhere on the network, and there is a "server," also somewhere on the network. Without the use of connection points, things flow only one way: method calls replace our water, the client replaces our faucet, and the server replaces the drain. This is way oversimplifying things, but the user "turns a handle" (that is, clicks a button, for example), and "stuff" (that is, method calls) "comes out of" the client. This "stuff that comes out" then "flows" over the network using DCOM. These calls "flow" to the server, which then collects them and acts like the "drain", or our sink. Here's Figure 2, which is almost exactly like Figure 1, but puts the client in place of the "source" and the server in place of the "sink," with the network in between:

Our client and server as the source and the sink.
Figure 2. Our client and server as the source and the sink.

OK, so now we have method calls flowing like water; wonderful. However, when the client calls methods, the server does all kinds of things that might be interesting to clients. So the server fires events all over the place. If our client doesn't care if the server fires events, it will just ignore them. However, if it cares, it will Advise() the server. Then the source-sink relationship of Figure 2 can be thought of in reverse:

The reverse of Figure 2.
Figure 3. The reverse of Figure 2.

Connection points come in when you have the following happening:

  1. The client is the source of a method call,
  2. The server sinks (that is, acts as the sink for) the method call.
  3. An "event call" comes out of the now-server-as-source.
  4. The client sinks the event call and does something.

As you can see, this is a round-trip. A method call goes from the client to the server, and then an event call goes from the server, to the client, as seen in Figure 4.

A round-trip.
Figure 4. A round-trip.

The Advise() step is done before item number 1 above, and the Unadvise() step (where the client goes back to being aloof) happens after item number 4. The points of contact on both the client and server and the Advise()ing and Unadvise()ing that happens all together form...


Whew... what a revelation... Let's start Step 5 before I get too carried away...

Step 5: Add the OnSayHello Event to the Event Source Interface DHelloWorldEvents

Let's plunge in, shall we? To add an event to the source, it's really, really easy. Just use the Visual C++ Wizards! Open up ClassView, and right-click the DHelloWorldEvents icon, and then click Add Method. The Add Method to Interface dialog box appears. Type OnSayHello in the Method Name box, and type [in] BSTR bstrHost in the Parameters box, as shown in Figure 5, below.

Adding the OnSayHello event to the DHelloWorldEvents event interface.
Figure 5. Adding the OnSayHello() event to the DHelloWorldEvents event interface.

Once you're done, click OK. ClassView should resemble Figure 6 below. Now click FileView, and find the HelloServ.idl file, under the Source Files folder. Right-click that baby, and then choose Compile. Watch the compiler work away in the Output window, and wait until the build is complete.

ClassView after adding the OnSayHello event.
Figure 6. ClassView after adding the OnSayHello event.

Once the build has been finished, click on ClassView. Right-click the CHelloWorld class, and then click Implement Connection Point. The Implement Connection Point dialog box appears. If you haven't compiled the IDL file yet like I told you to, Visual C++ will prompt you to do so. Figure 7, below, shows you how to select that you want to make the server able to fire off its OnSayHello event:

Figure 7. Specifying that we want to implement Connection Points for the DHelloWorldEvents event interface.

When everything looks like Figure 7, click OK. The Visual C++ IDE will now generate all the server-side code you need for Connection Points. Each time you change an event in the DHelloWorldEvents event interface, you need to do the (1) compile the IDL, (2) right-click CHelloWorld and choose Implement Connection Point, (3) check the box by DHelloWorldEvents, and (4) click OK steps.

Notes From the Rear

The final part of Step 5 which we have to take care of is firing the event. Remember, we declared the OnSayHello() event in the IDL file as:

HRESULT OnSayHello(BSTR bstrHost);
Listing 1. The declaration of the OnSayHello() event.

To fire the event from any CHelloWorld member function, just call Fire_OnSayHello(). It's a member function of a new base class, CProxyDHelloWorldEvents< > that the Implement Connection Points dialog box just added for us. To this end, let's add code to the CHelloWorld::SayHello() function to fire the event to the client:

STDMETHODIMP CHelloWorld::SayHello()

    // Get the network name of this computer

    if (!GetComputerName(szComputerName, &dwSize))
        return E_FAIL;    // failed to get the name of this computer

    // Say Hello to the client

    return S_OK;
Listing 2. Code to add to finish the CHelloWorld::SayHello() member function.

That's it! We're finished with Step 5. Click Next to go on to Step 6, or click Back to step back to Step 4 if you're browsing through the tutorial. If you have any questions, try clicking on Questions and Answers to go to the page with the good stuff, and then e-mail me at if you're still stuck.

<< Back | Next >>

Questions and Answers


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Brian C Hart
Software Developer (Senior) xyLOGIX, LLC
United States United States
From Fridley, Minnesota and I like computer programming! When I got started, I was working mostly with Windows GUI programming in C/C++. Then later on I worked with COM/DCOM for a school internship. I used COM/DCOM to write an ad hoc cluster server and job-running environment for a cluster of 24 Windows-based high-end visualization workstations. I moved on to C# and have been working in C# and Windows Forms ever since. I have yet to embrace Silverlight Smile | :)

You may also be interested in...

Comments and Discussions

GeneralMake Sure and Configure DCOM on Windows XP Pro SP2 Pin
Brian Hart26-Mar-05 10:09
memberBrian Hart26-Mar-05 10:09 
GeneralPlease Work Through the Tutorial Pin
Brian Hart10-Jan-05 0:17
memberBrian Hart10-Jan-05 0:17 
GeneralAdd Connection Point wizard fails to implement Fire_OnSayHello Pin
Kza Wah5-Jan-05 1:49
memberKza Wah5-Jan-05 1:49 
GeneralRe: Add Connection Point wizard fails to implement Fire_OnSayHello Pin
Brian Hart10-Jan-05 0:31
memberBrian Hart10-Jan-05 0:31 
GeneralRe: Add Connection Point wizard fails to implement Fire_OnSayHello Pin
ti-oh5-Feb-07 22:17
memberti-oh5-Feb-07 22:17 
GeneralXMLDOM.IDL solution Pin
Robert Bielik18-Mar-04 3:41
memberRobert Bielik18-Mar-04 3:41 
GeneralRe: XMLDOM.IDL solution Pin
Anonymous23-Mar-05 7:19
sussAnonymous23-Mar-05 7:19 
GeneralT2OLE macro unknown Pin
Stober2-Jan-04 6:08
memberStober2-Jan-04 6:08 
GeneralRe: T2OLE macro unknown Pin
shuklao26-Apr-04 5:12
membershuklao26-Apr-04 5:12 
GeneralRe: T2OLE macro unknown Pin
lasombra197925-Nov-04 23:33
memberlasombra197925-Nov-04 23:33 
GeneralRe: T2OLE macro unknown Pin
sanangel29-Jan-05 0:52
membersanangel29-Jan-05 0:52 
GeneralRe: T2OLE macro unknown Pin
Brian Hart29-Jan-05 9:29
memberBrian Hart29-Jan-05 9:29 
Generalxmldom.idl Missing Pin
elderdo2-Dec-03 12:16
memberelderdo2-Dec-03 12:16 
GeneralRe: xmldom.idl Missing Pin
Brian Hart2-Dec-03 12:50
memberBrian Hart2-Dec-03 12:50 
GeneralRe: xmldom.idl Missing Pin
elderdo4-Dec-03 5:07
memberelderdo4-Dec-03 5:07 
GeneralRe: xmldom.idl Missing Pin
Brian Hart10-Jan-05 0:29
memberBrian Hart10-Jan-05 0:29 
Or try the answer at[^]

Sincerely Yours,
Brian Hart
Department of Physics and Astronomy
University of California, Irvine
GeneralImplementation of Fire_OnsayHello Pin
Anonymous4-Feb-03 12:17
sussAnonymous4-Feb-03 12:17 
GeneralRe: Implementation of Fire_OnsayHello Pin
Brian Hart3-Jan-04 12:12
memberBrian Hart3-Jan-04 12:12 
GeneralI've a prob with the wizard creating IID_DHalloWeltEvents Pin
Benjamin Danzer3-Jul-02 13:53
memberBenjamin Danzer3-Jul-02 13:53 
GeneralRe: I've a prob with the wizard creating IID_DHalloWeltEvents Pin
Martin Schneider10-Jul-02 8:40
memberMartin Schneider10-Jul-02 8:40 
GeneralRe: I've a prob with the wizard creating IID_DHalloWeltEvents Pin
Horia Geaman9-Sep-02 10:16
memberHoria Geaman9-Sep-02 10:16 
GeneralRe: I've a prob with the wizard creating IID_DHalloWeltEvents Pin
Brian Hart10-Jan-05 0:22
memberBrian Hart10-Jan-05 0:22 
GeneralYo, Yo! Pin
Philip Patrick2-Jun-02 21:55
memberPhilip Patrick2-Jun-02 21:55 
GeneralRe: Yo, Yo! Pin
Brian Hart10-Jan-05 0:24
memberBrian Hart10-Jan-05 0:24 
GeneralThread context. Pin
Giles29-Mar-02 12:58
memberGiles29-Mar-02 12:58 
GeneralRe: Thread context. Pin
Brian Hart29-Mar-02 13:01
memberBrian Hart29-Mar-02 13:01 
GeneralRe: Thread context. Pin
Giles30-Mar-02 1:47
memberGiles30-Mar-02 1:47 
QuestionHaving a Question? Pin
Brian Hart2-Jan-02 16:59
memberBrian Hart2-Jan-02 16:59 
GeneralMIDL2025 error Pin
Anonymous6-Nov-01 4:25
memberAnonymous6-Nov-01 4:25 
GeneralRe: MIDL2025 error Pin
Anonymous8-Nov-01 23:09
memberAnonymous8-Nov-01 23:09 
GeneralRe: MIDL2025 error Pin
Christian Mogensen24-Jan-02 4:14
memberChristian Mogensen24-Jan-02 4:14 
GeneralRe: MIDL2025 error Pin
Anonymous15-Sep-02 23:09
sussAnonymous15-Sep-02 23:09 
GeneralRe: MIDL2025 error Pin
Anonymous21-Oct-02 2:12
sussAnonymous21-Oct-02 2:12 
GeneralRe: MIDL2025 error Pin
David A. Jones19-Feb-04 11:15
memberDavid A. Jones19-Feb-04 11:15 
GeneralRe: MIDL2025 error, fix Pin
martin.wangel@wipcore.se13-Oct-04 22:36
sussmartin.wangel@wipcore.se13-Oct-04 22:36 
GeneralRe: MIDL2025 error Pin
Anonymous19-Feb-04 12:25
sussAnonymous19-Feb-04 12:25 
Oprea Bogdan25-Jun-01 23:41
memberOprea Bogdan25-Jun-01 23:41 
Hidde Wallaart12-Sep-01 6:27
memberHidde Wallaart12-Sep-01 6:27 
Tassax12-Sep-01 7:05
memberTassax12-Sep-01 7:05 
QuestionWhy connection points? Pin
Anonymous9-May-01 0:54
memberAnonymous9-May-01 0:54 
AnswerRe: Why connection points? Pin
Sharat24-Oct-01 23:18
memberSharat24-Oct-01 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 12 Aug 2000
Article Copyright 2000 by Brian C Hart
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid