# WIN332Ole , pass by reference

**URL:** <https://www.ruby-forum.com/t/win332ole-pass-by-reference/190150>\
**Category:** Ruby\
**Created:** [June 17, 2010, 8:24am UTC](https://www.ruby-forum.com/t/win332ole-pass-by-reference/190150 "2010-06-17T08:24:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![george\_thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@george\_thomas](https://www.ruby-forum.com/u/george_thomas)\
**Post date:** [June 17, 2010, 8:24am UTC](https://www.ruby-forum.com/t/win332ole-pass-by-reference/190150/1 "2010-06-17T08:24:07Z")

</div>

Hi,

I am trying to call a method in an ATL (C++ based) dll created by myself  
through WIN32OLE of Ruby

The signature of the method in the idl file is something as follows

[id(37), helpstring(“method GetCustomArea”)] HRESULT GetCustomArea([out]  
LONG\* UpperLeft\_XCord, [out] LONG\* UpperLeft\_YCord, [out] LONG\* Width,  
[out] LONG\* Height, [out,retval] VARIANT\_BOOL\* ReturnVal);

In Ruby I have tried something as follows…

require ‘win32ole’  
a = WIN32OLE.new(“IDof the component”)  
c = a.GetCustomArea(nil,nil,nil,nil)

Further querying the value as(for the first out paramter)  
WIN32OLE::ARGV[0] does not give me a valid result.

I have also tried something as follows…

require ‘win32ole’  
a = WIN32OLE.new(“IDof the component”)  
include WIN32OLE::VARIANT  
dispid = a.ole\_method(‘GetCustomArea’).dispid  
a.\_invoke(dispid, [nil,nil,nil,nil,nil], [VT\_I4|VT\_BYREF,  
VT\_I4|VT\_BYREF,VT\_I4|VT\_BYREF,VT\_I4|VT\_BYREF,VT\_BOOL|VT\_BYREF])  
The error in this case is

WIN32OLERuntimeError: (in OLE method '\<dispatch id:37: )  
OLE error code:0 in   
  
Invalid number of parameters.  
from (irb): 5: in ‘\_invoke’  
from C:/…/bin/irb:12:in ‘’

Can some one point me in the right direction? I have several other  
methods in my component. All others are working fine. However , they do  
not have an [out] parameter.

Regards,  
George

---

<div class="post-metadata">

**Author:** ![george\_thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c77e96/32.png) [@george\_thomas](https://www.ruby-forum.com/u/george_thomas)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/win332ole-pass-by-reference/190150/2 "2010-06-17T16:22:41Z")

</div>

Hi

With \_invoke, you may set the initial values in the second  
argument as same type as specified in the third argument,  
and don’t include for [retval].  
So, please try to write as  
a.\_invoke(dispid, [0,0,0,0],

[VT\_I4|VT\_BYREF,VT\_I4|VT\_BYREF,VT\_I4|VT\_BYREF,VT\_I4|VT\_BYREF])  
.

Cheers

arton  
— George T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> GetCustomArea([out]  
> c = a.GetCustomArea(nil,nil,nil,nil)  
> dispid = a.ole\_method(‘GetCustomArea’).dispid  
> a.\_invoke(dispid, [nil,nil,nil,nil,nil],  
> [VT\_I4|VT\_BYREF,

VT\_I4|VT\_BYREF,VT\_I4|VT\_BYREF,VT\_I4|VT\_BYREF,VT\_BOOL|VT\_BYREF])
