# Win32ole: Pass by Reference

**URL:** <https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169>\
**Category:** Ruby\
**Created:** [November 14, 2007, 1:10pm UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169 "2007-11-14T13:10:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a9adbd/32.png) [@zxem](https://www.ruby-forum.com/u/zxem)\
**Post date:** [November 14, 2007, 1:10pm UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169/1 "2007-11-14T13:10:50Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![zxem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a9adbd/32.png) [@zxem](https://www.ruby-forum.com/u/zxem)\
**Post date:** [November 14, 2007, 4:03pm UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169/2 "2007-11-14T16:03:25Z")

</div>

On Nov 14, 2007 1:10 PM, zxem [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/232146)

Jano

---

<div class="post-metadata">

**Author:** ![zxem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a9adbd/32.png) [@zxem](https://www.ruby-forum.com/u/zxem)\
**Post date:** [November 14, 2007, 6:06pm UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169/3 "2007-11-14T18:06:00Z")

</div>

On Nov 14, 3:02 pm, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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!

---

<div class="post-metadata">

**Author:** ![zxem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a9adbd/32.png) [@zxem](https://www.ruby-forum.com/u/zxem)\
**Post date:** [November 14, 2007, 6:57pm UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169/4 "2007-11-14T18:57:32Z")

</div>

On Nov 14, 2007 6:05 PM, zxem [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![zxem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a9adbd/32.png) [@zxem](https://www.ruby-forum.com/u/zxem)\
**Post date:** [November 15, 2007, 11:47am UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169/5 "2007-11-15T11:47:04Z")

</div>

On Nov 14, 5:56 pm, Jano S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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;

```

---

<div class="post-metadata">

**Author:** ![zxem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a9adbd/32.png) [@zxem](https://www.ruby-forum.com/u/zxem)\
**Post date:** [November 17, 2007, 6:38am UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169/6 "2007-11-17T06:38:52Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![zxem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/a9adbd/32.png) [@zxem](https://www.ruby-forum.com/u/zxem)\
**Post date:** [November 15, 2007, 1:26pm UTC](https://www.ruby-forum.com/t/win32ole-pass-by-reference/120169/7 "2007-11-15T13:26:44Z")

</div>

On Nov 15, 10:41 am, zxem [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://rubyforge.org/tracker/index.php?func=detail&aid=15020&group_id=426&atid=1698)?

Cheers!  
Xin Zhao
