asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

ASP COM Objects with ATL 2.0
By Wayne Berry
Rating: 2.7 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Creating an Active Server Page Object

    On Feburary 17, Microsoft released Active Template Library (ATL) version 2.0, a predecssor to ATL 1.0. This release was in anticpation to the relase of Visual C 5.0 that will hit the streets March 17. ATL will be shipped in Visual C 5.0, but you can get an early start with Visual C 4.2b and ATL 2.0.

    In this issue we will demonstrate 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 creating your COM Object, you must install ATL 1.1 from Mircosoft's web site.

    Creating an Active Server Page COM Object can be accomplished in three Steps. The first step is too create the ATL Project. The second step involves merge the proxy/stub code. The third step is too add an ATL Object to the ATL project using the ATL Object Wizard. Once you have completed the three steps 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.

    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. Make sure that you download both:

    • The ATL
    • The ATL Object Wizard Technology Preview.

    [ATL Download]

    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.

    Create the Project

    1. Open Microsoft Developer Studio.
    2. File | New.
    3. From the New Dialog Select Project Workspace.
    4. At the bottom of the type list box select ATL COM AppWizard.
    5. In the Name Edit Box type ATLExample2.
    6. Press Create. A dialog called ATL COM AppWizard - Step 1 of 1 will appear.
    7. Check Allow merging of prozy/stub code.
    8. Click On Finish
    9. Click on OK.

    Figure 01 : ATL COM AppWizard - Step 1 of 1

    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 2, you will learn how to correctly merge the proxy/stub code. Though merging the proxy/stub code is not nesscary for Active Server Pages, it is nesscary if you want to later move the object to a transaction server.

    Step 2a : Add dlldatax.c to the Project

    1. Insert | Files into Project...
    2. Select dlldatax.c.
    3. Press Add.
    Figure 2 : Insert Files into Project Dialog

    Step 2b : Turn Precomplied Off For dlldatax.c

    1. Build | Settings...
    2. Expand each Setting by clicking on the + symbol in the Settings For: list box.
    3. 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.
    4. Click on the C/C++ Tab
    5. From the Category Drop down select Precompiled Headers.
    6. Change the Radio button to Not using precompiled headers.
    Figure 3 : Turn Precomplied Headers Off For Dlldatax.c

    Step 2c : Set _MERGE_PROXYSTUB

    1. Collapse Each Setting by clicking on the - symbol by each one.
    2. Click on Each Setting holding down the control key until all are selected.
    3. While in the C/C++ Tab, click on General.
    4. 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

    1. Build | Settings...
    2. Expand each Setting by clicking on the + symbol in the Settings For: list box.
    3. Select ATLExample2.idl from each of the settings. Holding down the crtl key will allow you to select all the references to ATLExample2.idl at once.
    4. Click on the Custom Build Tab.
    5. Click on the New Output File Button.
    6. Type in ATLExample2_p.c, and Press Return.
    7. Click on the New Output File Button.
    8. Type in dlldata.c, and Press Return.
    Figure 5 : Modify The Build Rule for ATLExample2.idl

    End of Step 2

    Don't compile yet, you will need to go on to Step 3 and add an ATL object before the project will compile correctly.

    In Step 3 we add an ATL Object to the already created ATL Project.

    Step 3a : Create an ATL Object

    1. Click on Insert | Component. The Component Gallery Dialog should pop up.
    2. Click on the ATL tab.

      Figure 6 : Component Gallery Dialog

    3. Click on ATL Object Wizard.
    4. Click on Insert and an the ATL Object Wizard Dialog should come up.
    5. Select Objects form the right list box.
    6. Select Simple Object from the left list box.

      Figure 7 : ATL Object Wizard Dialog

    7. Click on Next and the ATL Object Wizard Properties Dialog Box Should Appear.
    8. In the Short Name edit box Type ATLExample2. The rest of the edit boxes should fill in automatically.

      Figure 8 : ATL Object Wizard Properties Dialog

    9. Click on OK.
    10. Click on Close.

    End of Step 3

    Once done with the above, compile 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.

    To call the ATL object from an Active Server Page add this code to the .asp file:

    
    Set Obj = Server.CreateObject("Object.Object.1")
    
    

    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 Method

    This method is called on every page request, before any other method is called into the Object. Too add this method to the ATLExample2, put this code in Object.cpp:

    STDMETHODIMP CObject::OnStartPage(IDispatch *pid)
    {
    return S_OK;
    }

    You will also need to add

    STDMETHOD(OnStartPage)(IDispatch *pid);

    within Object.h under the public declaration of the CObject class.

    Finally you will need to add:

    [id(100)]
    HRESULT OnStartPage([in]IDispatch *pid);

    to ATLExample2.idl under the declaration of the IObject interface.

    OnEndPage Method

    This method is called on every page request, after all of the other methods are called. To add this method to the ATLExample2, put this code in Object.cpp:

    STDMETHODIMP CObject::OnEndPage()
    {
    return S_OK;
    }

    You will also need to add

    STDMETHOD(OnEndPage)();

    within Object.h under the public declaration of the CObject class.

    Finally you will need to add:

    [id(101)]
    HRESULT OnEndPage();

    to ATLExample2.idl under the declaration of the IObject interface.

    To download skeleton code that contains the results of first, second, third steps with the entry points go here:
    http://15seconds.com/files/030897.zip 20K.

    Note

    Although the skeleton code is a good example of the ATL technology, creating all your projects from the skeleton code would not work. The problem arises because the skeleton has the GUID number hardcoded. This would cause problem if two objects where created from the same skeleton code and were required to run on the same machine. It is best to follow all three steps for each unique object that you want to create.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Apr 22, 1997 - Active Server Components with VS 5.0
    A rewrite of part one of a four-part series on Active Server objects. A simple example of creating a Active Server Component in Visual Studio 5.0 using the Active Template Library 2.0. The example component retrieves the user's cookie, if not available issues a new 128-bit cookie. Included in the issue is the source code and step by step instructions. This issue has been rewritten to illustrate the use of Visual Studio 5.0 and ATL 2.0 in writing Active Server Components.
    [Read This Article]  [Top]
    Mar 16, 1997 - Debugging Active Server Objects
    Part two of a four-part series on Active Server components. In this issue 15 Seconds discuss how to write and debug an Active Server object that writes to the Event Log. Included in the issue is the source code and step by step instructions. This issue uses MSVC 4.2 and ATL 2.0
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers