next up previous contents
Next: 5.5 History Up: 5.4 Important issues about Previous: 5.4.4 Extensible Interfaces   Contents


5.4.5 Visual Basic© issue

A COM server implemented with LuaCOM can be used in VB with no trouble:

Public lc as Object

Set lc = CreateObject("MyCOMObject.InLuaCOM")

lc.showWindow

b = lc.getData(3)

lc.Quit

But if one wants to received events generated by a COM object implemented using LuaCOM, then it's necessary to use VB's Public WithEvents:

Public WithEvents obj as MyCOMObject.Application

Set obj = CreateObject("MyCOMObject.Application")

Private Sub obj_genericEvent()
  ' Put your event code here
End Sub

Here there is a problem: when VB assigns the result of CreateObject to obj variable, it tries to get an early bound interface (as far as I know, VB only uses late-bound interfaces with variables of type Object). LuaCOM does not work with early-bound interfaces (known as vtable). If you call any method using the obj variable, VB will throw an exception.

The solution we adopted was to accept a QueryInterface for a early-bound interface (thus allowing the use of Public WithEvents). Then the client must do a ``typecast'' to use correctly the COM object:

Public WithEvents obj_dummy as MyCOMObject.Application
Public obj as Object

Set obj_dummy = CreateObject("MyCOMObject.Application")
Set obj = obj_dummy

This way the client may call methods of the COM object using the obj variable.


next up previous contents
Next: 5.5 History Up: 5.4 Important issues about Previous: 5.4.4 Extensible Interfaces   Contents
Fabio Mascarenhas de Queiroz 2004-09-13