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 1.1
By Wayne Berry
Rating: 2.8 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    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 ATL

    Since 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

    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 ATLExample.
    6. Press Create. A dialog called ATL COM AppWizard - Step 1 of 2 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 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

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

    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

    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 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.
    4. Click on the Custom Build Tab.
    5. Click on the New Output File Button.
    6. Type in ATLExample_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 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.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Apr 27, 2004 - Develop and Customize Web Parts with Custom Tool Parts
    Tool Parts provide an interface for Web Part properties well beyond the capabilities of the default property pane. In this article Gayan Peiris shows how to customize Web Parts with custom Tool Parts.
    [Read This Article]  [Top]
    Apr 7, 2004 - Reusable Components in ASP.NET 2.0, Object Binding and Precompilation
    This article demonstrates how to create a reusable component in ASP.NET 2.0 and then consume it from an ASP.NET page. Also learn how the ObjectDataSource control can be used to directly bind the output of an object to the controls in an ASP.NET page and how precompilation can be used to increase the performance of the Web application and catch compilation errors.
    [Read This Article]  [Top]
    Mar 31, 2004 - Build a Managed BHO and Plug into the Browser
    Browser Helper Objects (BHOs) are COM components that communicate with Internet Explorer to enrich the browsing experience. Michele Leroux Bustamante returns to the world of COM to show you how to build a managed BHO with the help of the .NET Framework's COM interoperability features.
    [Read This Article]  [Top]
    Feb 18, 2004 - Customizing SharePoint Web Parts with Custom Properties
    In addition to creating custom Web Parts for SharePoint Portal Server, developers can actually create their own custom properties to further enhance Web Part appearance and behavior. Gayan Peiris explains the process and provides all the necessary code.
    [Read This Article]  [Top]
    Sep 26, 2003 - Accessing Shared Resources Using ASP.NET
    Accessing shared resources is a challenge for many ASP.NET developers. Tony Arslan explains how a simple serviced component can solve this infamous problem.
    [Read This Article]  [Top]
    Oct 2, 2002 - Function Pointers and COM
    Using callbacks and function pointers in VB can be risky and complicated. Ben Garcia explains his work-around for the function pointer issue he encountered while creating the VB version of his SNMP component.
    [Read This Article]  [Top]
    Sep 4, 2002 - Creating an SNMP Component - Part 2
    In part two of this intriguing article series, Ben Garcia shows how to build an updated and improved SNMP component in VC++ AND VB, and he briefly explains why limitations in VB make VC++ a better language for developing this type of application.
    [Read This Article]  [Top]
    Jul 23, 2002 - Creating an SNMP Component
    Ben Garcia sheds some light on the Simple Network Management Protocol (SNMP). First he provides a history of SNMP, then he dives right into its architecture. Finally, he shows how to build a COM component that communicates with SNMP-enabled devices.
    [Read This Article]  [Top]
    Jun 26, 2002 - Accessing Caller ID from the Web - Part 1
    Paul Apostolos begins his series on using Web services and the MSComm32.OCX component to access caller id information from a Web page. In part 1, learn how to write the Visual Basic program that runs on the server and updates a database with incoming callers.
    [Read This Article]  [Top]
    Nov 20, 2001 - Creating a Server Component with VB - Redesigned - Part 2
    Doug Dean explains different methods of retrieving and manipulating data from a database in a VB DLL so that it is ready to be rendered in a browser.
    [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