Microsoft® Windows® Script Component
Creating a Script Component Type Library
 Script Component Tutorial
Previous
Next

See Also


You can generate a type library for your Windows® Script Component containing information about its interfaces and members. In some host applications (such as Visual Basic), type libraries are necessary to enable events for the script component, while in other host applications, type libraries are optional. However, even if a type library is not required, generating one can make working with a script component easier and less error-prone in the host application.

Note   For information about using a type library in the host application, refer to the application's documentation.

To create a script component type library

For more precise control over generating type libraries, you can generate the type library dynamically from script inside the script component file, or you can use a command-line interface.

Generating Type Libraries Dynamically

The script component run-time includes an Automation interface implemented by the Scriptlet.TypeLib object. You can use this object in script to generate a type library from within the script component file. This is particularly useful for creating a type library automatically when the script component is registered.

To create a script component type library dynamically

  1. In script inside the script component file, create an instance of the Scriptlet.TypeLib object by using syntax such as the following:
    set oTL = CreateObject("Scriptlet.TypeLib")  ' In VBScript.
    var oTL = new ActiveXObject("Scriptlet.TypeLib");  // In JScript.
    
  2. Set the following properties of the Scriptlet.TypeLib object:
    Property/Method Description
    AddURL (Method) (Required) Adds the URL of the script component file from which to generate the type library.
    Path (Property) (Required) The file name for the type library, which can optionally include a path. If the Path property is not set, a type library, Scriptlet.tlb, is created in the same directory as the component.
    Doc (Property) A string containing any information that is stored in the registry with the type library information.
    GUID (Property) A GUID for the type library. (This is not the GUID for the script component.) If you do not provide one, the Scriptlet.TypeLib object will create one, but then the type library will have a different GUID on each machine.
    Name (Property) The internal name for the type library. This name is displayed in some applications, such as the Visual Basic Object Browser.
    MajorVersion (Property) An integer value you assign.
    MinorVersion (Property) An integer value you assign.

  3. Call the type library object's Write method to create the .tlb file, then register it.

  4. If you want to create an additional type library, call the TypeLib object's Reset method to clear the list of script component files in the AddURL property, reset the URLs and any other properties you want, and then call the Write method again.

For example, the following script in a <registration> element creates a type library dynamically.

Note   A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.

<registration
   description="My Test Component"
   progid="Component.TestScript"
   version="1"
   classid="{2154c700-9253-11d1-a3ac-0aa0044eb5f}">
   <script language="VBScript">
   <![CDATA[
      Function Register()
         Set oTL = CreateObject("Scriptlet.TypeLib")
         oTL.AddURL "d:\components\MyComponent.wsc"   ' Script component URL.
         oTL.Path = "d:\components\MyComponent.tlb"   ' .tlb path.
         oTL.Doc = "Sample component typelib"  ' Documentation string.
         oTL.GUID = "{a1e1e3e0-a252-11d1-9fa1-00a0c90fffc0}"
         oTL.Name = "MyComponentTLib" ' Internal name for tlb.
         oTL.MajorVersion = 1
         oTL.MinorVersion = 0
         oTL.Write ' Write tlib to disk.
         oTL.Reset ' Clear list of URLs in AddURL/.
      End Function
   ]]>
   </script>
</registration>

Command-line Interface

If you are comfortable using the Command Prompt window, you can call the Rundll32.exe program to create type libraries.

To create a type library from the command prompt

For example, the following command creates a type library called MyComponent.tlb from the script component MyComponent.wsc (the command is wrapped for clarity):

rundll32.exe c:\winnt\system32\scrobj.dll,GenerateTypeLib 
   -name:MyComponentTLib  -file:d:\components\MyComponent.tlb 
   -doc:\"Sample component typelib\" 
   -guid:{a1e1e3e0-a252-11d1-9fa1-00a0c90fffc0} -major:1  -minor:0 
   d:\components\MyComponent.wsc

Troubleshooting Type Libraries

The process of generating a type library can fail for various reasons. The error you see might not be clear enough in all cases to make it obvious where the problem lies. If you are unable to generate a type library, review the following list of likely causes for the failure.