Using Scriptlets as COM Components in ASP

ID: Q224980


The information in this article applies to:
  • Microsoft Internet Information Services version 5.0


SUMMARY

Microsoft Windows Script Components allow developers to write COM components, known as Scriptlets, in languages such as VBScript or JavaScript. These components can then be called from any COM-compliant programming environment, such as Microsoft Visual C++, Visual Basic, or Active Server Pages (ASP).


MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.


The following example shows how to create and register a sample scriptlet on your system and then call it from ASP.
  1. Copy the following code and save it as "Example.sct" on your desktop:
    
    <SCRIPTLET>
      <REGISTRATION
        Description="DHTML Button Scriplet"
        ProgID="DHTML.Button.Scriptlet"
        Version="1.0" >
      </REGISTRATION>
    
      <IMPLEMENTS ID="Automation" TYPE="Automation">
        <METHOD NAME="CreateButton">
          <PARAMETER NAME="txt"/>
          <PARAMETER NAME="url"/>
          <PARAMETER NAME="fore"/>
          <PARAMETER NAME="back"/>
          <PARAMETER NAME="glow"/>
          <PARAMETER NAME="width"/>
        </METHOD>
      </IMPLEMENTS>
    
      <SCRIPT LANGUAGE="VBScript">
        Option Explicit
        Function CreateButton(txt,url,fore,back,glow,width)
          Dim strNormal
          Dim strGlow
          strNormal = "this.style.background='" & back & "';"
          strGlow   = "this.style.background='" & glow & "';"
    
          CreateButton = vbCrLf & "<table border=""0""
    cellpadding=""5"">" & vbCrLf
          CreateButton = CreateButton & "<tr><td align=""center"""
          CreateButton = CreateButton & " language=""JavaScript""" &
    vbCrLf
          If width <> "" Then
            CreateButton = CreateButton & " width=""" & width & """"
          End If
          CreateButton = CreateButton & " style=""background:" & back
    & ";"
          CreateButton = CreateButton & "color:" & fore & ";""" &
    vbCrLf
          CreateButton = CreateButton & " onMouseover=""" & strGlow &
    """" & vbCrLf
          CreateButton = CreateButton & " onMouseout=""" & strNormal &
    """>" & vbCrLf
          CreateButton = CreateButton & "<a href=""" & url & """"
          CreateButton = CreateButton & " style=""text-
    decoration:none;"
          CreateButton = CreateButton & "color:" & fore & ";"">" &
    vbCrLf
          CreateButton = CreateButton & txt & "</a></td></tr>" &
    vbCrLf
          CreateButton = CreateButton & "</table>" & vbCrLf
        End Function
      </SCRIPT>
    </SCRIPTLET> 
    Notes:
    • The ProgID field in the Registration section refers to the scriptlet's Class ID.
    • After registering the scriptlet, an entry for the class ProgID and CLSID are created in the registry at the following locations:
      
      HKEY_CLASSES_ROOT\DHTML.Button.Scriptlet
      HKEY_CLASSES_ROOT\DHTML.Button.Scriptlet\CLSID 
    • Using the CLSID default value, you can obtain the class GUID, which can be used to build the path to the following two keys:
      
      HKEY_CLASSES_ROOT\CLSID\{class GUID goes here}\InprocServer32
      HKEY_CLASSES_ROOT\CLSID\{class GUID goes here}\ScriptletURL 
    • These two keys can be especially useful in obtaining the following troubleshooting information:
      InprocServer32 = The path to the handler DLL (for example Scrobj.dll)
      ScriptletURL = The path to the scriptlet


  2. Right-click on the scriptlet and select Register, and then click OK for the confirmation dialog.


  3. Save the following ASP code as "Example.asp" in a Web folder on your IIS computer with Script Access enabled:
    
    <%@LANGUAGE="VBSCRIPT"%>
    <% Option Explicit %>
    
    <html>
    <body>
    <%
      Dim objButton
    
      Set objButton = Server.CreateObject("DHTML.Button.Scriptlet")
    
      Response.Write objButton.CreateButton("Back to
    Home","/","white","black","#0000ff","100")
      Response.Write
    objButton.CreateButton("Microsoft","http://www.microsoft.com","#ff
    ff00","magenta","#33cc33","100")
      Response.Write
    objButton.CreateButton("MSDN","http://msdn.microsoft.com","black",
    "red","brown","100")
    %>
    </body>
    </html> 


  4. When you browse the example page, you should see three DHTML hover buttons.


For more information, please see the Microsoft Scripting Technologies Web site.

Keywords :
Version : winnt:5.0
Platform : winnt
Issue type : kbinfo


Last Reviewed: February 2, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.