Help with WIN32OLE and WIN32OLE_EVENT.new, second post!

  • Thread starter Dominic Sisneros
  • Start date
D

Dominic Sisneros

I am trying to control a Microstation application through its VBA api.
I am able to connect to the object and control it but I am now trying to figure
out how to deal with Microstation's event handling. In Microstation
VBA you declare
that a class implements an Event interface and make sure the class
implements all the methods.
You then call a method on the Application object. In example below
SaveHandler implements 'ISaveAsEvents'

app = WIN32OLE.new('MicrostationDGN.Application.1')
app.visible = TRUE
app.AddSaveAsEventsHandler SaveHandler

I tried to create a class that implements the methods in 'ISaveAsEvents'

class SaveHandler

def AfterRedraw
end

def BeforeRedraw
end
end

but get a segmentation fault because of type mismatch

I also tried to use the WIN32OLE_EVENT class

ev = WIN32OLE_EVENT.new(app, 'IViewUpdateEvents')

=> No such interface supported



Here is a win32ole_pp of the 'AddSaveAsEventsHandler' method

#<WIN32OLE_METHOD:0x32c7ac4: AddViewUpdateEventsHandler
name="AddViewUpdateEventsHandler",
dispid=1610744231,
helpstring="",
helpcontext=2674,
helpfile="C:\\PROGRA~1\\Bentley\\Program\\MICROS~1\\MicroStationVBA.chm",
invoke_kind="FUNC",
invkind=1,
return_type="VOID",
return_type_detail=["VOID"],
return_vtype=24,
size_opt_params=0,
size_params=1,
offset_vtbl=1720,
visible?=true,
event?=false,
event_interface=nil,
params=
[#<WIN32OLE_PARAM:0x32ad494: EventHandler
name="EventHandler",
ole_type="IViewUpdateEvents",
ole_type_detail=["PTR", "USERDEFINED", "IViewUpdateEvents"],
default=nil,
input?=true,
output?=false,
optional?=false,
retval?=false>]>


*********


Here is an example that they show in the help file for Microstation.
the following is the class file

' This is the implementation of clsEventHandlers. It has Implements
statements declaring that it implements anevent interface.



Implements IViewUpdateEvents

'
' Methods for the IViewUpdateEvents
'
Private Sub IViewUpdateEvents_AfterRedraw(TheViews() As View,
TheModels() As ModelReference, ByVal DrawMode As MsdDrawingMode)
If UBound(TheModels) < 0 Then
' This is a normal update. Everything is being redrawn
End If
End Sub

Private Sub IViewUpdateEvents_BeforeRedraw(TheViews() As View,
TheModels() As ModelReference, ByVal DrawMode As MsdDrawingMode)

End Sub


******************

Here is how the initialize it. Everything not declared defaults to
the Application object


Private oEventHandlers As clsEventHandlers

Sub InstallHandlers()
RemoveHandlers
Set oEventHandlers = New clsEventHandlers
AddViewUpdateEventsHandler oEventHandlers
End Sub

Sub RemoveHandlers()
If Not oEventHandlers Is Nothing Then
RemoveViewUpdateEventsHandler oEventHandlers
End If
Set oEventHandlers = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,221
Latest member
TrinidadKa

Latest Threads

Top