# WIN32OLE - problem with argv

**URL:** <https://www.ruby-forum.com/t/win32ole-problem-with-argv/121925>\
**Category:** Ruby\
**Created:** [December 2, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/win32ole-problem-with-argv/121925 "2007-12-02T23:51:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [December 2, 2007, 11:51pm UTC](https://www.ruby-forum.com/t/win32ole-problem-with-argv/121925/1 "2007-12-02T23:51:19Z")

</div>

Hello,

I’m having a problem trying to pass parameters by reference with  
WIN32OLE::ARGV. What I’m actually trying to do is getting access to  
OneNote 2007 as described here…

> **[What's New for Developers in OneNote 2007 (Part 1 of 2)](https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2007/ms788684(v=office.12)?redirectedfrom=MSDN)**

…but using Ruby instead.

Here’s my little program:

* * *

require “win32ole”  
one = WIN32OLE.new(“onenote.application”)

class ON\_CONST  
end  
WIN32OLE.const\_load(one, ON\_CONST)

a\_string = ‘’

## one.GetHierarchy(nil,ON\_CONST::HsPages,a\_string)

GetHierarchy should pass the Hierarchy of OneNote pages into  
“a\_string” (I think). However, WIN32OLE::ARGV leaves “a\_string” empty:

p WIN32OLE::ARGV  
prompt\> [-2147352572, 4, “”]

Using invoke won’t make a difference:

one.invoke(“GetHierarchy”, nil,ON\_CONST::HsPages,a\_string)  
p WIN32OLE::ARGV  
prompt\> [-2147352572, 4, “”]

Does anybody have an idea what I’m getting wrong? (I’m using Ruby  
1.8.6)

Kind regards,

Rainer

P.S.: Any example for a successful pass by reference is appreciated,  
even with another Office program like Excel or Word.

P.P.S.: I already have read the earlier discussion from Nov. 14 about  
the same problem.

---

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [December 3, 2007, 12:32am UTC](https://www.ruby-forum.com/t/win32ole-problem-with-argv/121925/2 "2007-12-03T00:32:16Z")

</div>

Hello,

Rainer wrote:

> Here’s my little program:
> 
> * * *
> 
> require “win32ole”  
> one = WIN32OLE.new(“onenote.application”)
> 
> class ON\_CONST  
> end  
> WIN32OLE.const\_load(one, ON\_CONST)
> 
> a\_string = ‘’
> 
> one.GetHierarchy(nil,ON\_CONST::HsPages,a\_string)

I have not used OneNote 2007, so I’m not sure, but  
could you try to use empty string (="") instead of nil as 1st argument?

one.GetHierarchy("",ON\_CONST::HsPages,a\_string)

Regards,  
Masaki S.

---

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [December 3, 2007, 12:56am UTC](https://www.ruby-forum.com/t/win32ole-problem-with-argv/121925/3 "2007-12-03T00:56:48Z")

</div>

Masaki S. wrote:

> > one.GetHierarchy(nil,ON\_CONST::HsPages,a\_string)
> 
> one.GetHierarchy("",ON\_CONST::HsPages,a\_string)

Or try to use WIN32OLE#\_invoke method.  
include WIN32OLE::VARIANT  
one.\_invoke(dispid, ["", ON\_ONST::HsPages, a\_string],  
[VT\_BSTR, VT\_I4, VT\_BSTR|VT\_BYREF])  
The dispid should be dispatch id of GetHierarchy method.

Regards,  
Masaki S.

---

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [December 3, 2007, 2:31am UTC](https://www.ruby-forum.com/t/win32ole-problem-with-argv/121925/4 "2007-12-03T02:31:29Z")

</div>

On 3 Dez., 00:56, Masaki S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> [VT_BSTR, VT_I4, VT_BSTR|VT_BYREF])
> 
> ```
> 
> The dispid should be dispatch id of GetHierarchy method.
> 
> Regards,  
> Masaki S.

Dear Masaki,

thank you very much, that did the trick! Now I’m getting a massive XML  
string as promised!

Kind regards,

Rainer
