Introduction

During discussions in forums, I come across many people who want to write COM/ATL DLL, but don't know how to create properties, methods or raise events from component or strive for fundamental knowledge to create them. For them, I had written this article in VC++ 6.0. Since Visual Studio 6 is now out of support, many beginners requested me for the same article using Visual Studio 2005/2008 as there is much GUI difference between the two.

So, I am presenting the same article using Visual Studio 2005 and as it’s a new article, I have to provide readers with something new, otherwise they will reject this article. .NET application is slowly eating into Visual C++ share of applications. So to follow popular demand, I will show how to use COM component in .NET application instead of Unmanaged Application. As it is a beginner article, I am included a few extra screenshots in the article. Please don't flame for using the same.

Table of Contents

Creating ATL Component

Using it in Visual C# Application (.NET 2005)

Creating ATL Component

Let us go step by step to create an ATL component in Visual Studio 2005:

Open Visual Studio 2005, and Click on File| New | Project menu, which will show you the following File-Save dialog box, where you can provide a name for your new project. Here I put the name as SimpleATLCom and it is advisable to choose the destination folder, where you want to create your project, otherwise it will clutter your Document Folder. Press OK to confirm your changes. This will create a blank ATL component.

Enter new Interface name in ATL Simple Object Wizard. You will see rest of the details are auto filled by Visual Studio development environment when you begin typing the interface name. Also check the Connection Point check box in the Option Tab which provides component ability to fire events.

Figure 4: ATL Simple Object

Figure 5: Select Connection Point Check Box

Now if you check the following IDL (Interface Definition Language) will be generated and included into your project:

Now add connection points into the main interface. For adding it, right click on CSimpleCom and click ADD | Add Connection Point. The following screenshot will appear:

Figure 10: Chose Add Connection Point

Choose > button to move _ISimpleComEvents source interface to implement connection point and click on finish. A new function Fire_TotalMarks is added to CSimpleCom class which can be used to raise event.

Figure 11: Add Connection Wizard

Now code all properties and functions present in CSimpleCom class, i.e. Add Class Variable for ComMarks, ATLMarks and StudentName for storing information coming from the outer world. After coding, our class would look like this:

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

Can you say anything about setting the version number of the COM/ATL DLL? I can't find out how to do it.

Apology for late reply, please let me know you are looking for Interface Version Or COM/ATL DLL version, as both are different topic and you might require different way to achieve same

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

I am running windows 8 ( started VS 2008 as admin) and after running the c# i am getting

Apologies for replying late.. let me build environment based on Windows8, will get bck to you on that

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

my vote 5.
question to _ISimpleComEvents_Event and _ISimpleComEvents_TotalMarksEventHandler, I don't see any definition of these two symbols, but acutall when typing them, they can be recognized. can you give more infomation to them? Thanks.

6. Now add Event almost in the same way, we add method in interface. Now right click on _ISimpleComEvents and Add | Add method.

I'm using VS2008 pro. When i right-clicked _ISimpleComEvents on class view, i only see Add | Function or Variable...
When i added, i dont see the event added into the .idl instead added into SimpleATLCom_i.h.

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David CrowNever mind - my own stupidity is the source of every "problem" - Mixture

Thanx ThatsAlok.
I have builded a simple COM/ATL DLL by VC2010 just like u. And the COM object has event too.
I test it by VC#, uses easy and correct. But I wanna use it in VC++ program, I dont know how to handle the event.
Did u know how to use it in VC++? (VS2005, 2008 or 2010 will be ok). Can u give a sample project? Thanx a lot.