Connection Points Example for VC++6 and VB Needed

VB is Easy: Just DoEvents or WithEvents.
But how do I get connection points up and running with Visual Studio 6?

I want to do mostly pressing wizards and popup menus. Almost no coding...

As an example: I have an IKid object that sends a "WantHotterWaterEvent" to three sinks.

Thanks, Moshe
Who is Participating?
ianBConnect With a Mentor Commented:

I am answering this question so it can be saved as a PAQ. I have refunded the points mflam used in this question.

Community Support @ Experts Exchange
>> I want to do mostly pressing wizards and
>> popup menus. Almost no coding..
That is what VB is for.  In VC you will have to do a decent amount of programming.  The MFC wizzards will get you started, but after that...
SAMPLE: Connpts.exe Implements Connection Points in MFC Apps
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

mflamAuthor Commented:
I will restate the question, and then explain why I rejected this answer.

QUESTION: I Need a "tutorial" of adding an event (connection point) to a server side ATL Simple Object.
I want to do it with the least amount of coding, using the most of the "Implement Connection Points" and "Insert New Class / ATL Class" wizards.
If adding a line of ATL is sufficient, I wish to do so.

1. I am fluent with MSDN.  
This is no help.
2. I wish to do this in ATL not MFC.

3. I even have an answer of my own, except that it is not the best one:
I open a sepparate project, and
in the Full-Control (Same with MFC ActiveX control wizard) I can add "events".  
Then on the simple ATL object I "implement connection point" with the .tlb from the Full Control.

Thanks  Moshe
Have you tried the tutorial in MSDN that explains how to add events to your control..

POLYGON: The ATL Tutorial
I think your method is good enough. The other way is to add the event interface to the IDL file so that you can build a type library from it.
mflamAuthor Commented:
Thank you, chensu and naveenkohli for your comments. As I said, I know the MSDN and controls. I'm looking for adding a connection point in a SIMPLE ATL command. (There's an old fasioned article in the MSDN about that.)

If anybody knows of a good answer, (I find it hard to believe there is no new way to do it all from the VC6 IDE interface) I will be very happy.

ADVAthanksNCE,  Moshe
mflamAuthor Commented:
I found my answer! On the online MSDN!
Sorry people.
I'll post a short tutorial from what I learn there. (Q194179 ATLEVNT.EXE)

But that article is to capture events. I thought you wanted to fire event from your object.
mflamAuthor Commented:
I would like to answer my own question (took 3 days to find answer). How do I do this?
This is important question and good answer IS NOT TO BE FOUND(!) on MSDN or internet.
I am putting it on my own site, but thought you people would like to see it too.
Here goes (next comment: Actually answer)
mflamAuthor Commented:
The Answer: Making simple ATL Obj Events
[RMB is "Right Mouse Button"]
[CP  is "Connection Point"]
Most of this tutorial is in the
"Class View" tab of Project Explorer.

[Make Proj and object]
Make an ATL project. ("ASimpServ")
Add a SIMPLE OBJECT to the ATL.("ASimp")
Before OKing it:
   Check: Supports IConnectionPoints.
   Check: Supports ISupportErrorInfo.

[Make property and method]
Click on + of CASimp
RMB on internal IASimp
 Add property: (long AProp, no params)
 Add method: (SayHi, no params)

[Add event fit for VB]
RMB on _IASimpEvents
 Add method: (void AEvent, no params)
 Add method: (void AAnotherEv, no prms)
 NOTE: Must be void for VB.

[Get event to fire when needed]
[...Build, ImplementCP, FireEvent]

RMB on CASimp
 Implement Connection Point
 Choose the _ISimpEvents
 OK and Build.

(Let's see what happened)
Additions to our code are:
1. A new proxy class with 2 methods:
2. IDL file has:
 interface of events
 dispinterface of events
 coclass [default, source] events
3.CProxyASimpEvents in Class View.
4.CProxyASimpEvents template in .h file
5.In CASimp header (ASimp.h):
   #includes proxy.
   :inherits from proxy.
   CP MAP entries added.

[... now fire the event]
(We will fix up our property)
RMB the CASimp
Add variable (long m_AProp)

Click '+' sign of CASimp (open CASimp)
DClick put_AProp
Add code:
 m_AProp = newVal;
 if (newVal > 90)
    MessageBox(NULL, Too hot",
               "ASimp says", MB_OK);
    Fire_AEvent(); // It's so easy!
(NOTE: Use Ctrl-Space to complete words
 like Fire_... and Messa...)

DClick get_AProp
Add code:
 *val = m_AProp;

DClick SayHi
Add code:
 MessageBox(NULL, "Hi",
            "From ASimp", MB_OK);

Your ready to run in VB!
mflamAuthor Commented:
Continuation of Answer: VB ATL Client
Now the VB client just uses the
1. Reference you object
  browse to the dll and OK it all)
2. Add to your code:
Public WithEvents obj as  ASimp
Sub Command1_Click
Set obj = CreateObject(ASimpPrj.ASimp)

obj.AProp = 22
msgbox obj.AProp

obj.AProp = 100
msgbox obj.AProp
3. Now click the obj and find the AEvent event for this object.
You should get an automatic SUB
Sub On_AEvent()
End Sub
4. Add to your sub a msgbox
 MsgBox "vb client received ASimp event"

5. Try it!

Have fun,  Moshe Flam
whats the difference between your method and the one described in Polygon tutorial. I believe there is none.

anyway, its great that you have finally found the soultion you were looking for.

Peace :-)
Isn't it the same as the method described in the ATL documentation?

Step 5: Adding an Event
mflamAuthor Commented:
Thank you very much.

Yes, naveen kohli, the Polygon is the same, except for one small point,
which caused me to think it wasn't :-(
It's an example of a "Full control".
Since the MFC ActiveX Control wizard has an "add event", I had presumed that "full control" support would be different from the support for an ATL Simple Object.
I kept looking, till I found the example (probably from VC5) and figured it out myself.

One good thing about my tutorial (I think) is that it points out a few caveats that you must abide by, and omits the need to do the rest of the tut, just directly what you want to do.
On the other hand, I didn't add the nice pictures.

Oh well,
here comes my next q, and this time I'll listen. (BTW naveen in Hebrew is "We will understand").

Thanks again, Moshe
All Courses

From novice to tech pro — start learning today.