Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Implement the CallByName function using the TLI library

Total Hit ( 5390)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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:

Click here to copy the following block
' Class.cls
Public Function MyFunc (FirstParam, SecondParam) As String
:
End Function

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

Click here to copy the following block
Dim obj As Object
Dim First, Second
Dim obj As Object
Dim result As String

' create the object
Set obj = CreateObject("MyServer.Class")
' call MyFunc
result = CallByName(obj, "MyFunc", VbMethod, First, Second)

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

Click here to copy the following block
Dim TLI As New TLIApplication
Dim obj As Object
Dim First, Second
Dim obj As Object
Dim result As String

' create the object
Set obj = CreateObject("MyServer.Class")
' call MyFunc
result = 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.



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.