VB Type Library Registration Utility
Register, Unregister and Manage Type Libraries on your system
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:
- Complete Registry control
- Common Dialogs without COMDLG32.OCX
- Set Left and Right Margin of Text Boxes and Combo Boxes
- Using ShellExecute from Visual Basic - start any document from its filename only
- Store Objects against a Control's Tag or ItemData property.
Calling Unicode Functions in DLLs with String Parameter
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 ever 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:
- 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. You can refer to the ODL and IDL source code in the Type Libraries section for
more details on building your own Type Libraries containing API declares.
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.
|