Win32ole: Pass by Reference

All,

I am using Ruby 1.8.6 now and trying to so a pass by reference COM
call through win32ole.

The code looks like this: (I am not really calling Excel)


excel = WIN32OLE.new(“excel”)
excel.getCell(cell, column, row)

The first parameter I need to pass into getCell on line2 is a complex
object(not String/double).
Could anyone please teach me how to do this call in Ruby?

Cheers!

On Nov 14, 2007 1:10 PM, zxem [email protected] wrote:


The first parameter I need to pass into getCell on line2 is a complex
object(not String/double).
Could anyone please teach me how to do this call in Ruby?

Look at 1.9 WIN32OLE documentation. The last paragraph discusses the
returning by reference (in short, you’ll find the result in
WIN32OLE::ARGV).

There are some interesting threads about this in the archive. Look for
Masaki S.'s posts (he is the author/maintainer).
One of them is this:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/232146

Jano

On Nov 14, 3:02 pm, Jano S. [email protected] wrote:

excel = WIN32OLE.new(“excel”)

There are some interesting threads about this in the archive. Look for
Masaki S.'s posts (he is the author/maintainer).
One of them is this:http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/232146

Jano

Hi,

I went through all the existing threads before I posted this one
because I did not fully understand them. Could anyone give me some
more detailed examples.

Cheers!

On Nov 14, 2007 6:05 PM, zxem [email protected] wrote:

excel = WIN32OLE.new(“excel”)
because I did not fully understand them. Could anyone give me some
more detailed examples.

Can you specify the problem in more detail? Is it that

(1) you need to pass an object to the method,
or
(2) the method returns the complex object, and you actually do not
need to pass it in,
or
(3) both?

If you can specify the exact API (if it is public) it would be easier
to help you.
So for now:

for (1) I think that’s easy. WIN32OLE.new(type)

for (2): try passing 0 or nil as the parameter, and read the result
from WIN32OLE::ARGV.first
if 0/nil doesn’t work then create an empty object and pass that. Try
inspecting ARGV to find out what stuff does it contain.

(I don’t remember why but) in some cases I used
WIN32OLE#invoke(method, *args) to call the COM object.

On Nov 14, 5:56 pm, Jano S. [email protected] wrote:

(2) the method returns the complex object, and you actually do not
for (2): try passing 0 or nil as the parameter, and read the result
from WIN32OLE::ARGV.first
if 0/nil doesn’t work then create an empty object and pass that. Try
inspecting ARGV to find out what stuff does it contain.

(I don’t remember why but) in some cases I used
WIN32OLE#invoke(method, *args) to call the COM object.

Great thanks for your help.

Option 2 solved my problem.

My sample code:

  curve.getNonWingProperties(
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0);

        tenor_date_out = WIN32OLE::ARGV[0];
        domestic_currency_out = WIN32OLE::ARGV[1];
  foreign_currency_out = WIN32OLE::ARGV[2];
  is_face_domestic_out = WIN32OLE::ARGV[3];
  is_booking_domestic_out = WIN32OLE::ARGV[4];
  ATM_style_out = WIN32OLE::ARGV[5];
  atTheMoneyVolatility_out = WIN32OLE::ARGV[6];
  atTheMoneyVolIsMissing_out = WIN32OLE::ARGV[7];
  puts tenor_date_out.GetSerialDouble;

Hello,

zxem wrote:

I raised a bug related to win32ole.c weeks ago. Could anyone who is
interested in this topic take a look at this

http://rubyforge.org/tracker/index.php?func=detail&aid=15020&group_id=426&atid=1698?
Sorry, I have not noticed this topic.
And I have fixed this problem in ruby_1_8 branch.
Thank you for your reporting.
Regards,
Masaki S.

On Nov 15, 10:41 am, zxem [email protected] wrote:

I am using Ruby 1.8.6 now and trying to so a pass by reference COM
object(not String/double).
(1) you need to pass an object to the method,
for (1) I think that’s easy. WIN32OLE.new(type)

            0,
        atTheMoneyVolatility_out = WIN32OLE::ARGV[6];
        atTheMoneyVolIsMissing_out = WIN32OLE::ARGV[7];
        puts tenor_date_out.GetSerialDouble;

Hi all,

I raised a bug related to win32ole.c weeks ago. Could anyone who is
interested in this topic take a look at this
http://rubyforge.org/tracker/index.php?func=detail&aid=15020&group_id=426&atid=1698?

Cheers!
Xin Zhao