Published: Friday, May 26, 2000
Building a Simple COM Component with Visual C++, Part 2
Read Part 1
In Part 1 we discussed binomial coefficients and how to start the
COM component building process in Visual C++. In this part we'll continue to work through the steps
of building the COM component! (Interested in learning more about binomial coefficients? Be sure to
visit the extended readings!)
Recall that in Part 1 we left off with selecting to create an
ATL COM AppWizard Project named Math. From that first dialog box we are taken into the
ATL COM AppWizard, which contains only one step. The Wizard can be seen to the right.
Make sure you choose to create a DLL and leave the three checkboxes unchecked. When you are ready,
click on the Finish button. At that point you will be presented with a dialog box that lists the files
the wizard will create. Click OK and the needed skeleton files will automatically be generated.
While the Wizard has created the skeleton files for the Math project, we still have to
create a class in the project that contains the properties and methods we need. To do this, we will
add a Simple ATL Object. To do this, go to the ClassView and right click on the Math classes
text; select the option New ATL Object. At this point you should be presented with the following dialog
box:
Choose to add a simple object and click Next. You will now be taken to a dialog box into which you can
enter the properties for the new simple object, as shown below:
Simply enter the value Comb in the Short Name text box. The rest of the text boxes will be
filled out automatically. Note that the ProgID text box has a value of Math.Comb. This is
the ProgID we'll use in our ASP page to instantiate our COM component (Server.CreateObject("Math.Comb")).
Take a moment to click on the Attributes tab in the above dialog box. This shows the threading model,
interface, and aggregation types for the component. For this example, leave the default values selected.
By adding a new simple ATL object, a class, CComb, has been added to our project. Also the
interface IComb has also been added. This interface determines how the outside world (an ASP
page, for example) sees the COM component. To add properties and methods to our component we will add
methods and properties to this interface. The interface's properties and methods are mapped to public
member functions in the class CComb.
In Part 3 we'll look at how to add the Comb method
to our IComb interface and how to tie a CComb member function to this interface
method!
Read Part 3
Read Part 1