| Creating a Active Server Page Object Active Template Library version 2.0 has been released since the publication of this issue. However, the March 8th 1997 Issue of 15 Seconds cover version 2.0. In this issue we will demostrate how to create a COM Object using Mircosoft's Active Template Library. The COM Object that we will create can be used in an Active Server Page to provide additional functionality. Before you begin createing your COM Object, you must instal ATL 1.1 from Mircosoft's web site. Creating an Active Server Page COM Object can be accomplished in two Steps. The first step is too create the ATL Project. The second step involves merge the proxy/stub code. Once done you have skeleton code that you can add functionality too. There are several interesting entry points to the COM Object that are useful when the object is called from a Active Server Page. You can also download the skeleton code with the entry points added. Installing ATLSince the release of this issue Mircosoft released version 2.0 of the Active Template Library. We are perserved a copy of atlinst.exe version 1.1 and have made it avaiablable on our server.Before you get started creating the COM Object, you must install the Active Template Library from Mircosoft's homepage. Since ATL uses Microsoft Developer Studio, and Microsft Visaul C++ you must have the 4.2b Version of MSVC installed before installing ATL. http://15seconds.com/files/atlinst.exe Create the Project - Open Microsoft Developer Studio.
- File | New.
- From the New Dialog Select Project Workspace.
- At the bottom of the type list box select ATL COM AppWizard.
- In the Name Edit Box type ATLExample.
- Press Create. A dialog called ATL COM AppWizard - Step 1 of 2 will appear.
- Check Allow merging of prozy/stub code.
- Click On Finish
- Click on OK.
Figure 01 : ATL COM AppWizard - Step 1 of 2 
End of Step 1 Now that the project is created you will need to go onto Step 2 to merge the proxy stub code.
In Step 1 you will learn how to correctly create an Active Template Library Project so that you can use it as a Active Server Page Obejct.
In Step 2, you will learn how to correctly merge the proxy/stub code. Add dlldatax.c To the Project - Insert | Files into Project...
- Select dlldatax.c.
- Press Add.
Figure 2 : Insert Files into Project Dialog
Turn Precomplied Off For dlldatax.c - Build | Settings...
- Expand each Setting by clicking on the + symbol in the Settings For: list box.
- Select dlldatax.c from each of the settings. Holding down the crtl key will allow you to select all the references to dlldatax.c at once.
- Click on the C/C++ Tab
- From the Category Drop down select Precompiled Headers.
- Change the Radio button to Not using precompiled headers.
Figure 3 : Turn Precomplied Headers Off For Dlldatax.c
Set _MERGE_PROXYSTUB - Collapse Each Setting by clicking on the - symbol by each one.
- Click on Each Setting holding down the control key until all are selected.
- While in the C/C++ Tab, click on General
- In the preprocessor definitions add _MERGE_PROXYSTUB to the end separted by a comma
Figure 4 : Set _MERGE_PROXYSTUB
Modify The Build Rule for ATLExample.idl - Build | Settings...
- Expand each Setting by clicking on the + symbol in the list box.
- Select ATLExample.idl from each of the settings. Holding down the crtl key will allow you to select all the references to ATLExample.idl at once.
- Click on the Custom Build Tab.
- Click on the New Output File Button.
- Type in ATLExample_p.c, and Press Return.
- Click on the New Output File Button.
- Type in dlldata.c, and Press Return.
Figure 5 : Modify The Build Rule for ATLExample.idl
End of Step 2 Once done with the sections above, click on OK to exit the Project Setting Dialog and complie the project. Compiling the project will automatically register the newly Created ATL COM Object. If you move the DLL to another machine, you must register the object with regsvr32.exe.
After you have created the Active Server COM Object, you need to have it do something. The following are enterance points that you can add to your COM Object. OnStartPage This method is called on every page request, before any other method is called into the Object. Too add this method to the ATLExample, put this code in ATLExample1.cpp:STDMETHODIMP CATLExample1::OnStartPage(IDispatch *pid) { return S_OK; }
You will also need to add STDMETHOD(OnStartPage)(IDispatch *pid);
within ATLExample1.h under the public declaration of the CATLExample1 class. Finally you will need to add: [id(100)] HRESULT OnStartPage([in]IDispatch *pid);
to ATLExample.idl under the declaration of the IATLExample1 interface. OnEndPage This method is called on every page request, after all of the other methods are called. To add this method to the ATLExample, put this code in ATLExample1.cpp:STDMETHODIMP CATLExample1::OnEndPage() { return S_OK; }
You will also need to add STDMETHOD(OnEndPage)();
within ATLExample1.h under the public declaration of the CATLExample1 class. Finally you will need to add: [id(101)] HRESULT OnEndPage();
to ATLExample.idl under the declaration of the IATLExample1 interface. Active Server Page Sample Code To call the ATLExample object from an Active Server Page add this code to the .asp file. <% Set Obj = Server.CreateObject("ATLExample.ATLExample1.1") %>
Download To download skeleton code that contains the results of first and second step go here: http://15seconds.com/files/021797.zip 16K.
|