An earlier thread explains how a callback with return parameters can
be used with Win32OLE. The example it gives returns a value of 'true'
to the 'cancel' parameter of a NewWindow2 event in Internet Explorer,
to prevent the window from displaying. And it works fine.

However NewWindow2 also allows the 'ppdisp' parameter to be configured
- you supply a value that is another InternetExplorer OLE object. This
is very useful if you want to script popup windows in IE - otherwise
you don't have a handle to the automatically created popup. I have
tried various ways of returning such a parameter, and in all cases my
new OLE object is ignored.

Does anyone know if it is possible to return 'out args' more complex
than Booleans in win32ole events? If so, how?

For reference, here is the sample code that returns a simple parameter
successfully:

require 'win32ole'

ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ie.gohome
ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents2')
ev.on_event_with_outargs('NewWindow2') {|ppdisp, cancel, args| 
    # Called when you click on a link with a target of a new window
    puts 'No I will not open this link in a new window!'
    args[1] = true

    # The most obvious alternative seems to be:
      # $popup = WIN32OLE.new('InternetExplorer.Application')
      # $popup.width = 100
      # args[0] = $popup 
    # but $popup does not get used for the new window
}
ev.on_event('OnQuit') {|*args| $LOOP = FALSE } 

$LOOP = TRUE
while ($LOOP)
  WIN32OLE_EVENT.message_loop
end

__END__