# Win32OLE: how to pass parameters by reference?

**URL:** <https://www.ruby-forum.com/t/win32ole-how-to-pass-parameters-by-reference/80969>\
**Category:** Ruby\
**Created:** [January 2, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/win32ole-how-to-pass-parameters-by-reference/80969 "2007-01-02T17:42:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![breko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@breko](https://www.ruby-forum.com/u/breko)\
**Post date:** [January 2, 2007, 5:42pm UTC](https://www.ruby-forum.com/t/win32ole-how-to-pass-parameters-by-reference/80969/1 "2007-01-02T17:42:49Z")

</div>

Hi,

I need to call an OLE method that takes a VARIANT argument, and fills  
it with data. How can I accomplish this? Somewhere in the ruby-cvs  
attic I’ve found WIN32OLE\_VARIANT, unfortunately it is removed now.

Long obj.GetX(varX As Variant)

long is success/error, varX is the actual value for X.  
invoke\_kind of the method is FUNC.

Thanks

---

<div class="post-metadata">

**Author:** ![breko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@breko](https://www.ruby-forum.com/u/breko)\
**Post date:** [January 3, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/win32ole-how-to-pass-parameters-by-reference/80969/2 "2007-01-03T23:08:43Z")

</div>

In message “Win32OLE: how to pass parameters by reference?”  
on 07/01/03, “Jan S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I need to call an OLE method that takes a VARIANT argument, and fills  
> it with data. How can I accomplish this? Somewhere in the ruby-cvs  
> attic I’ve found WIN32OLE\_VARIANT, unfortunately it is removed now.

No, WIN32OLE\_VARIANT is Ruby 1.9 feature.  
Sorry, Ruby 1.8 does not support WIN32OLE\_VARIANT.

In Ruby 1.8, WIN32OLE#\_invoke method may help you.

oleobj.\_invoke(dispid, [value], [WIN32OLE::VARIANT::VT\_VARIANT])

The dispid is the dispatch id of the OLE method to call.  
The value is the data which you want to pass.

Regards,  
Masaki S.

---

<div class="post-metadata">

**Author:** ![breko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@breko](https://www.ruby-forum.com/u/breko)\
**Post date:** [January 4, 2007, 12:13am UTC](https://www.ruby-forum.com/t/win32ole-how-to-pass-parameters-by-reference/80969/3 "2007-01-04T00:13:02Z")

</div>

On 1/3/07, Masaki S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> In Ruby 1.8, WIN32OLE#\_invoke method may help you.
> 
> oleobj.\_invoke(dispid, [value], [WIN32OLE::VARIANT::VT\_VARIANT])
> 
> The dispid is the dispatch id of the OLE method to call.  
> The value is the data which you want to pass.
> 
> Regards,  
> Masaki S.

In the meantime I have found the answer in your older answers. Thank  
you for all of them. The trick was to google for ‘output’ instead of  
‘reference’ 😉

In this case, using WIN32OLE::ARGS was enough to get what I need.

I have added a doc patch (7557) to ruby tracker to document that. (I  
have copied pieces from your examples if you don’t mind).

Thanks again.  
Jano

---

<div class="post-metadata">

**Author:** ![breko](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea666f/32.png) [@breko](https://www.ruby-forum.com/u/breko)\
**Post date:** [January 6, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/win32ole-how-to-pass-parameters-by-reference/80969/4 "2007-01-06T19:18:08Z")

</div>

Jan S. schrieb:

> In the meantime I have found the answer in your older answers. Thank  
> you for all of them. The trick was to google for ‘output’ instead of  
> ‘reference’ 😉
> 
> In this case, using WIN32OLE::ARGS was enough to get what I need.
> 
> I have added a doc patch (7557) to ruby tracker to document that. (I  
> have copied pieces from your examples if you don’t mind).

Jan, this is great. Enhancing the existing documentation of a library  
after having solved a problem. May others (me included) be inspired by  
your example.

Regards,  
Pit
