# Help with WIN32OLE and WIN32OLE\_EVENT.new, second post!

**URL:** <https://www.ruby-forum.com/t/help-with-win32ole-and-win32ole-event-new-second-post/139645>\
**Category:** Ruby\
**Created:** [June 5, 2008, 6:52pm UTC](https://www.ruby-forum.com/t/help-with-win32ole-and-win32ole-event-new-second-post/139645 "2008-06-05T18:52:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [June 5, 2008, 6:52pm UTC](https://www.ruby-forum.com/t/help-with-win32ole-and-win32ole-event-new-second-post/139645/1 "2008-06-05T18:52:33Z")

</div>

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
