# Win32 COM events

**URL:** <https://www.ruby-forum.com/t/win32-com-events/81885>\
**Category:** Ruby\
**Created:** [January 16, 2007, 12:55am UTC](https://www.ruby-forum.com/t/win32-com-events/81885 "2007-01-16T00:55:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [January 16, 2007, 12:55am UTC](https://www.ruby-forum.com/t/win32-com-events/81885/1 "2007-01-16T00:55:35Z")

</div>

Hello All.

I want to translate the following VB code to Ruby. Does anybody know  
how to handle these events?

Dim WithEvents myOBJ As SomeOBJ

Private Sub myOBJ\_SomeEvent(ByVal nCommand As Integer,  
ByRef cResult As String)

* * *

Also things like this…

Event SomeFunction(ByVal n as Integer)

SomeFunction(5)

Thanks in Advance.

---

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [January 16, 2007, 4:10pm UTC](https://www.ruby-forum.com/t/win32-com-events/81885/2 "2007-01-16T16:10:16Z")

</div>

On 1/16/07, Tim U. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> * * *
> 
> Also things like this…
> 
> Event SomeFunction(ByVal n as Integer)
> 
> SomeFunction(5)

If you want to receive COM events,  
see WIN32OLE library, class WIN32OLE\_EVENT,  
Programming Ruby, chapter on windows support,  
thread  
[http://groups.google.com/group/comp.lang.ruby/browse\_frm/thread/98e22146a1c503e7/37b07544198f5bf1%2337b07544198f5bf1](http://groups.google.com/group/comp.lang.ruby/browse_frm/thread/98e22146a1c503e7/37b07544198f5bf1%2337b07544198f5bf1)  
[http://groups.google.com/group/ruby-talk-google/browse\_frm/thread/1dc66ac34191f20c/3e16fc7ea887a00a%233e16fc7ea887a00a](http://groups.google.com/group/ruby-talk-google/browse_frm/thread/1dc66ac34191f20c/3e16fc7ea887a00a%233e16fc7ea887a00a)  
and my doc patch  
[http://rubyforge.org/tracker/?func=detail&aid=7557&group\_id=426&atid=1700](http://rubyforge.org/tracker/?func=detail&aid=7557&group_id=426&atid=1700)

If you want to rewrite the code without interacting with COM, it’s  
another story.  
In that case, write in more detail what are you trieng to achieve.

---

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [January 25, 2007, 3:48am UTC](https://www.ruby-forum.com/t/win32-com-events/81885/3 "2007-01-25T03:48:28Z")

</div>

> If you want to rewrite the code without interacting with COM, it’s  
> another story.  
> In that case, write in more detail what are you trieng to achieve.

I have read the win32 doc, and I have read your doc patch. I don’t  
know if .invoke and on\_event are compatible in some way or not.  
though.

The example says…  
router = WIN32OLE.new(‘SomeOleObject.Something’)  
ev = WIN32OLE\_EVENT.new(router, nil)

ev.on\_event {|\*args| default\_handler(\*args)}  
ev.on\_event(“NavigateComplete”) {|url| navigate(url)}

in my case many of the params passed in are by reference and need to  
be modified by the code that is handling the event. In other words the  
ole object is requesting information my code by invoking events.

Do I still use the .invoke function here?
