How to communicate directly with IIS in a VB DLL


ow to communicate directly with IIS in a VB DLL

The following article describes how to to communicate directly with IIS’s intrinsic objects from your VB DLL.

For example, suppose on your ASP page you instanciate an object called “myDll.myObject”:

<%
DIM oMyObject
Set oMyObject = Server.CreateObject(“myDll.myObject”)
‘Other code here
%>

If you want this DLL to be able to talk directly to the IIS objects (eg. the Reponse and Request objects) then you will need to add a reference to ‘Microsoft Active Server Pages Object Library’ in the DLL. Next, use the following code as a template in the DLL:

Option Explicit
Private zoRequest As ASPTypeLibrary.Request
Private zoResponse As ASPTypeLibrary.Response
private zoAspScripting As ASPTypeLibrary.ScriptingContext

‘This is automatically called when your DLL is instantiated by the ASP page
Sub OnStartPage(AspScripting As ASPTypeLibrary.ScriptingContext)
On Error GoTo ErrFailed
‘Store the various ASP object you want to use
Set zoAspScripting = AspScripting
Set zoResponse = zoAspScripting .Response
Set zoRequest  = zoAspScripting .Request

Exit Sub

ErrFailed:
‘Error handling here
End Sub

‘This is also automatically called when the ASP page releases its
‘reference to your DLL.
Sub OnEndPage()
‘Release references to the ASP objects
Set zoResponse = Nothing
Set zoRequest  = Nothing
Set zoAspScripting = Nothing
End Sub

Using this code you can write directly from you DLL to the web browser of the client using the Response Object.

source:http://www.visualbasic.happycodings.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s