The new vbAccelerator Site - more VB and .NET Code and Controls
 Resources
  Type Libraries &nbsp
 

VB Type Library Registration Utility

 
 

Register, Unregister and Manage Type Libraries on your system

 


 NOTE: this code has been superceded by the version at the new site.



&nbsp

VB TLB registration utility

Download the VB Type Library Registration Utility and Source Code (58kb)

&nbsp Before you Begin &nbsp
&nbsp The source code project requires the IShellFolder Extended Type Library v1.2 (ISHF_Ex.tlb). Make sure you have loaded and registered this before trying the project - I recommend using this utility to register it! &nbsp

Whilst all systems are provided with the regsvr32 tool for register ActiveX controls and DLLs, there is not an equivalent tool available for Type Libraries. This page provides a Type Library registration utility that allows you to register Type Libraries more reliably than using VB's Project->References dialog. It also allows you to unregister Type Libraries and browse through all the type libraries installed on the system, including deleting entries for old and deleted items.

The site source code used in this sample includes:

Calling Unicode Functions in DLLs with String Parameters
The code also demonstrates how to make the following calls from Visual Basic:
  • LoadTypeLib
  • RegisterTypeLib
  • UnRegisterTypeLib
  • CLSIDFromString
These calls are interesting because they only have a Unicode implementation, even under Win9x. Visual Basic coders are used to calling ANSI functions in DLLs, and setting up all string parameters to DLL calls as (for example) ByVal lpszPath As String. When every you use ByVal with a string parameter in a declare, you are telling VB to convert its internal Unicode representation of the string into an ANSI version, and then to pass a pointer to the ANSI string to the function. When the function returns, VB converts the ANSI string back to unicode and puts the data back into your string.

When you are using a Unicode function, however, you need to ensure Visual Basic never makes the ANSI conversion. That means you can't use the As String construct in Unicode function declares. So when a Unicode function call requires a String variable parameter, you have three possibilities:
  1. Modify ByVal .. As String to ByRef .. As Byte and pass the first element of a byte array containing the Unicode (double byte) representation to the parameter.

' 1. - Using Byte Arrays:
'
Private Declare Function LoadTypeLib Lib "oleaut32.dll" ( _
    pFileName As Byte, pptlib As Object) As Long

Dim sLib As String
Dim suLib() As Byte
Dim errOK As Long
Dim tlb As Object

   sLib = "C:\Windows\System\ISHF_Ex.TLB"
' Basic automatically translates strings to Unicode Byte arrays
' but doesn't null-terminate, so you must do it yourself
   suLib = sLib & vbNullChar

' Pass first byte of array
   errOK = LoadTypeLib(suLib(0), tlb)

  • Modify ByVal .. As String to ByVal .. As Long and pass StrPtr(sThis) where sThis is your string to the Long parameter.

  • ' 2. - Using String Pointers:
    '
    Private Declare Function LoadTypeLib Lib "oleaut32.dll" ( _
        ByVal pFileName As Long, pptlib As Object) As Long

    Dim sLib As String
    Dim errOK As Long
    Dim tlb As Object

       sLib = "C:\Windows\System\ISHF_Ex.TLB"

    ' Pass StrPtr to the String argument:
       errOK = LoadTypeLib(StrPtr(sLib), tlb)

  • Write a Type Library. Then you can specify that the parameter is of the BSTR Automation type, which happens to be the native VB implementation for strings. vbAccelerator is aiming to have some articles on building Type Libraries towards the end of 1999.
  • With Win2000 Microsoft have announced that new function prototypes on the system will not have a corresponding ANSI version, and therefore there will be an increasing number of calls which need to be made with direct Unicode strings.






    TopBack to top
    ResourcesBack to Resources

    &nbsp
     

    About  Contribute  Send Feedback  Privacy

    Copyright © 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
    Last updated: 15 November 1999