Implement the CallByName function using the TLI library

Thanks to the undocumented TlbInf32 library you can emulate the VB6 CallByName() function in VB5 too. First, add a reference to the “TypeLib Information” type library in your project. This library contains the InvokeHook function, which is very similar to CallByName.

Let’s suppose you have an ActiveX DLL called MyServer.dll that exposes this function:

' Class.clsPublic Function MyFunc (FirstParam, SecondParam) As String:End Function

In VB6 you’re able to call MyFunc() with:

Dim obj As ObjectDim First, SecondDim obj As ObjectDim result As String' create the objectSet obj = CreateObject("MyServer.Class")' call MyFuncresult = CallByName(obj, "MyFunc", VbMethod, First, Second)

The following code demonstrates how to do the same in VB5:

Dim TLI As New TLIApplicationDim obj As ObjectDim First, SecondDim obj As ObjectDim result As String' create the objectSet obj = CreateObject("MyServer.Class")' call MyFuncresult = InvokeHook(obj, "MyFunc", INVOKE_FUNC, Second, First)

The sintax of InvokeHook() is simple: the first parameter is the object which you want to work, the second one indicates the name of the property or method to call, the third parameter is the type of call being made and can be one of the following values:

  • INVOKE_PROPERTYGET to assign a property value (vbGet in CallByName)
  • INVOKE_PROPERTYPUT to retrieve a property value (vbLet in CallByName)
  • INVOKE_PROPERTYPUTREF to assign an object reference to a property (vbSet in CallByName)
  • INVOKE_FUNC for a sub or function call (vbMethod in CallByName)
The last parameter is a ParamArray used to pass the list of parameters to the function being invoked: note that parameters must be in reverse order. Note that InvokeHook can be useful even under VB6, in that it lets you work around a bug of VB6’s CallByName.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS