Implement the CallByName function using the TLI library

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes