# Win32OLE, COM, pointer arguments

**URL:** <https://www.ruby-forum.com/t/win32ole-com-pointer-arguments/62846>\
**Category:** Ruby\
**Created:** [June 8, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/win32ole-com-pointer-arguments/62846 "2006-06-08T18:35:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![graham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4af34b/32.png) [@graham](https://www.ruby-forum.com/u/graham)\
**Post date:** [June 8, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/win32ole-com-pointer-arguments/62846/1 "2006-06-08T18:35:32Z")

</div>

I am trying to call a COM DLL with Win32OLE, but I am running into an  
issue with passing an argument to the method call. The following works  
in Perl:

– begin Perl

use Win32::OLE;  
use Win32::OLE::Variant;

my $engine = Win32::OLE-\>new(‘X.X’) or die 'Cannot load engine DLL:  
'.$!;  
my $system = ‘C:\path\to\dir’;  
my $mode = 0;  
my $retVal = Variant(VT\_I4|VT\_BYREF, 0);  
my $rc;

$rc = $engine-\>Execute($system,$mode,$retVal);  
print “Return Code: “.Win32::OLE-\>LastError.”\n”;  
print "Return Val: ".$retVal;

– end Perl

In ruby I think it should look like this:

– begin Ruby

require ‘win32ole’  
engine = WIN32OLE.new(‘X.X’)

retVal = 1  
rc = 1

rc = engine.Execute(‘C:\path\to\dir’,0,retVal)

print "Return Code: ",retVal

– end Ruby

When I run the ruby code, the DLL executes and processes the directory,  
but I need to be able to get back the return value. Unlike in Perl,  
ruby doesn’t seem to be able to generate a variant object to be passed  
to the method call. The DLL expects an integer pointer for the third  
argument, COM signature VT\_I4|VT\_BYREF, but I’m at a loss as to how to  
properly pass this so I can retrieve the value after execution.

I’ve also tried olegen.rb to generate a ruby class for the DLL, but this  
seems to have the same exact problem.

Thanks,  
Graham
