Compartir a través de


Creating Visual Basic COM Components for ASP

COM components use Automation to present an easy way of creating object instances. Components that use Automation are known as Automation servers. Clients of Automation servers are known as Automation controllers. When an ASP script creates an instance of an object from your component, it is acting as an Automation controller.

To create a Visual Basic component for ASP

  1. Create an ActiveX? DLL project. An ActiveX DLL is a COM component that exposes its methods to clients through Automation.

  2. Make sure that your component supports the Apartment threading model, as this will improve the performance of your application. Click General, Project Properties, then Apartment in the Threading Model section.

  3. Include references in your VB project to the COM+ Services Type Library and the Microsoft? Active Server Pages Object Library. To do this from Visual Basic, click Project, click References, then select the boxes for the appropriate type libraries.

  4. If your component must access ASP built-in objects, call the GetObjectContext function to create an instance of the COM+ ObjectContext object. Use the instance of the ObjectContext object to connect to the ASP built-in objects.

The following example code shows you how to use the Visual Basic programming language to obtain a reference to the ASP built-in Response object.

Public Function GetResponse() 
  Dim objContext As ObjectContext 
  Dim objResponse As Response 
  Set objContext = GetObjectContext() 
  Set objResponse = objContext("Response") 

  ' You can use either of the following two lines. 
  objContext("Response").Write ("Hello World") 
  objResponse.Write ("Hello World") 
End Function 

See Also

Other Resources

ActiveX Controls