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.
For example, if you are using Visual Basic as your host application, use the References dialog box to select a script component's type library. This allows you to bind events to the script component and make them visible in Visual Basic. In addition, when you are writing Visual Basic code that references the script component, Visual Basic uses the type library information in statement completion and in the Object Browser so you can easily see and use properties, methods, and events that the script component exposes.
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
A .tlb file is generated for the script component with the same name as the script component file, written to the folder where the .wsc file is, and registered in the Windows registry.
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.
The script component run-time includes an Automation interface implemented by the Component.GenerateTypeLib 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
set oTL = CreateObject("Scriptlet.GenerateTypeLib")
Property/Method | Description |
---|---|
AddURL | (Method) Adds the URL of the script component file from which to generate the type library. You can call this method property multiple times to include multiple script components in the type library. |
Path | (Property) The path and file where the type library will be written. The default path is the current directory and the default name is the name of the script component file with a .tlb extension. If the object is unable to create the specified library, it defaults to creating a type library called component.tlb. |
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 GenerateTypeLib object will create one, but then the type library will have a different GUID on each machine. The GUID must be exactly in this format, where x represents a hex value:
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} |
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. |
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.GenerateTypeLib") oTL.AddURL "d:\components\MyComponent.wsc" ' Script component URL. oTL.AddURL "d:\components\YourComponent.wsc" 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>
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
rundll32.exe path\scrobj.dll,GenerateTypeLib options
Where:
-name:Name |
---|
-file:Path |
-doc:\"Doc\" |
-guid:GUID |
-major:MajorVersion |
-minor:MinorVersion |
-URL:AddURL |
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 -URL:d:\components\MyComponent.wsc
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.
Note It is possible to define a script component in which the get and put property functions have different numbers of arguments, but you cannot create a type library for that script component.
Script Component File Contents | Creating Registration Information | Checking For Errors in Script Component Files | Script Component Files and XML Conformance