Trouble with WIN32OLE obj, methods that return other objects

Dear Friends,

Is is possible in Ruby to instantiate WIN32OLE objects that are returned
by a method call on other WIN32OLE objects?

The situation is the following. There is a
NsComCom2.CommunicationComponent
OLE (COM) object (for communicating with a Navision ERP system). It has
a CreateoutMessage (yes, misspelled, it’s Microsoft, so don’t be
surprised) method that returns another OLE object (a message object). So
I

So I do

cc2 = WIN32OLE.new(“NsComCom2.CommunicationComponent”)
and it works fine.

now, I would try to

msg = cc2.CreateoutMessage(“Message queue://.\private$\NIF”)

and it does something but it does not instantiate the right object in
the msg variable, because the methods I’d expect msg to have are not
available. Yes, I know there are some casing quirks, so I tried
createoutMessage, createoutmessage, create_out_message, createOutMessage
and whatever, but it never worked. mgs.class just returns WIN32OLE.

Any ideas?

An Excel example will just do fine - say, call a method on a Sheet that
returns a Range object into a variable, and then call some method of the
Range object instance.

Wow… an Excel example won’t do, as I methods returning other object
work just fine with Excel, but not with these objects I use. But I think
the objects are not buggy, because they work in VBScript, there must
just be some special kind of behaviour.

My complete code is:

require ‘win32ole’

cc2 = WIN32OLE::new ‘NsComCom2.CommunicationComponent’
mqba = WIN32OLE::new ‘MSMQBusAdapter.MSMQBusAdapter’
cc2.AddBusAdapter mqba, 1
mqba.OpenWriteQueue ‘.\private$\NIF’ , 1 , 0
mqba.OpenReplyQueue ‘.\private$\NIF-REPLY’ , 0 , 0
outMsg = cc2.CreateoutMessage(‘Message queue://.\private$\NIF’)
outStr = outMsg.GetStream
outStr.Write(“he”)
outMsg.Send(0)

and I get an error stating outStr is a NilClass…

I have more focus on the problem now. It seems COM objects returned by a
method call on another COM object CAN be instantiated in Ruby EXCEPT
when it’s an IStream object. But why and how to work around it?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs