# Using win32ole "connect" method on Ironruby

**URL:** <https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866>\
**Category:** IronRuby\
**Created:** [November 9, 2010, 5:06pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866 "2010-11-09T17:06:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 9, 2010, 5:06pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/1 "2010-11-09T17:06:15Z")

</div>

When trying to use the connect method inside the win32ole module.  
Ironruby pops up:

“undefined method ‘connect’ for WIN32OLE:Class”

I see that has been logged as an official issue at:

[http://ironruby.codeplex.com/workitem/4612](http://ironruby.codeplex.com/workitem/4612)

However, it has not been assigned to anyone to fix and previous  
questions on it went unanswered. I personally have many programs using  
this method that I would like to use through Ironruby without rewriting  
using .net methods.

Just testing to see if this issue is on anybody’s radar. Is it simple or  
complex to solve? I understand there are probably many issues more  
important than this but I am just wanting to know if I need to start  
rewriting my programs or will this issue be resolved in the near future.

Timothy

---

<div class="post-metadata">

**Author:** ![tuatha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b4bc9f/32.png) [@tuatha](https://www.ruby-forum.com/u/tuatha)\
**Post date:** [November 9, 2010, 5:35pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/2 "2010-11-09T17:35:23Z")

</div>

On Tue, Nov 9, 2010 at 5:06 PM, Timothy B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> questions on it went unanswered. I personally have many programs using  
> this method that I would like to use through Ironruby without rewriting  
> using .net methods.
> 
> Just testing to see if this issue is on anybody’s radar. Is it simple or  
> complex to solve? I understand there are probably many issues more  
> important than this but I am just wanting to know if I need to start  
> rewriting my programs or will this issue be resolved in the near future.

Why rewriting your programs if you can just add a patch to ironruby?

---

<div class="post-metadata">

**Author:** ![tuatha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b4bc9f/32.png) [@tuatha](https://www.ruby-forum.com/u/tuatha)\
**Post date:** [November 9, 2010, 5:46pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/3 "2010-11-09T17:46:11Z")

</div>

I would love to write a patch to ironRuby. However, I am not sure about  
how to do that. I am not even really sure where to look for the issue in  
the ironruby library, nor I do I really have git fully figured out to  
submit my patch back to ironruby.

I am still trying to get up to speed on how all this works  
(contributing). I will be glad to try. Any direction towards where to  
find and solve this issue would help!

---

<div class="post-metadata">

**Author:** ![tuatha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b4bc9f/32.png) [@tuatha](https://www.ruby-forum.com/u/tuatha)\
**Post date:** [November 9, 2010, 8:28pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/4 "2010-11-09T20:28:05Z")

</div>

Checkout(by that I mean get a copy) the code from github.

The IronRuby implementation of win32ole is in  
Languages/Ruby/Libs/win32ole.rb, it uses System.\_\_ComObject from the  
.NET  
world to implement the interface (as the header comment tells one).

If you are familiar with COM Objects (I am not) and you know how to  
achieve  
the functionality of WIN32OLE.connect with System.\_\_ComObject C# then it  
should be straight obvious what you need to do. Just use some interop  
magic  
in win32ole.rb to utilize the .NET world.

Your implementation should comply with the standard WIN32OLE  
implementation  
in ruby, you can easily look it up in  
[http://ruby-doc.org/stdlib/libdoc/win32ole/rdoc/classes/WIN32OLE.html#M001628](http://ruby-doc.org/stdlib/libdoc/win32ole/rdoc/classes/WIN32OLE.html#M001628),  
just  
click [Source].

If you are not familiar with COM in C#, well, there are plenty of  
tutorials  
on the net.

Just implement the function as clean as possible, commit, add a testcase  
to  
Languages/Ruby/Tests/Interop/com/win32ole\_spec.rb, commit, verify if it  
works with your code and the testcase, make a pull request on github.

---

<div class="post-metadata">

**Author:** ![tuatha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b4bc9f/32.png) [@tuatha](https://www.ruby-forum.com/u/tuatha)\
**Post date:** [November 9, 2010, 8:02pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/5 "2010-11-09T20:02:57Z")

</div>

Contributing is easy: fork the repo, make the changes, add tests  
covering the new functionality (ideally as specs to  
Languages/Ruby/Tests/mspec/rubyspec), run all the tests (irtests command  
in Languages\Ruby\Scripts), and if everything passes push your changes  
to your fork and send a pull request to the mailing list.

See [https://github.com/ironruby/ironruby/wiki/Getting-the-sources](https://github.com/ironruby/ironruby/wiki/Getting-the-sources)

Tomas

---

<div class="post-metadata">

**Author:** ![tuatha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b4bc9f/32.png) [@tuatha](https://www.ruby-forum.com/u/tuatha)\
**Post date:** [February 25, 2011, 10:24pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/6 "2011-02-25T22:24:11Z")

</div>

It appears to be that the WIN32OLE.connect method cannot be fixed as  
long as the WIN32OLE is class in IronRuby. This is b/c the connect  
method substitutes for the new(initialize) method when called. I don’t  
believe ruby allows you to create a class instance with out calling the  
new method. Therefore, I see (2) possible solutions:

1. Change WIN32OLE to a module not a class and have the ability to call  
connect or new.

2. Add a connect method to WIN32OLE class and change the way connect has  
to be coded to connect to a running instance of an application.

I have attached a file showing a possible way to accomplish solution #1.

My questions are:  
Which way should it go?  
And are there issues that would come up if WIN32OLE were a module and  
not a class?

Thanks for any help on this.

Timothy

---

<div class="post-metadata">

**Author:** ![tuatha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b4bc9f/32.png) [@tuatha](https://www.ruby-forum.com/u/tuatha)\
**Post date:** [November 9, 2010, 8:34pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/7 "2010-11-09T20:34:56Z")

</div>

Thanks for the help. I will see what I can do.

Timothy

---

<div class="post-metadata">

**Author:** ![tuatha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b4bc9f/32.png) [@tuatha](https://www.ruby-forum.com/u/tuatha)\
**Post date:** [March 11, 2011, 6:35pm UTC](https://www.ruby-forum.com/t/using-win32ole-connect-method-on-ironruby/198866/8 "2011-03-11T18:35:06Z")

</div>

> I don’t believe ruby allows you to create a class instance with out calling the  
> new method.

maybe #allocate?
