Forum: IronRuby Using win32ole "connect" method on Ironruby

Posted by Timothy Barnes (barnes7td)
on 2010-11-09 17:06
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

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
Posted by Andrius Bentkus (Guest)
on 2010-11-09 17:35
(Received via mailing list)
On Tue, Nov 9, 2010 at 5:06 PM, Timothy Barnes <lists@ruby-forum.com> 
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?
Posted by Timothy Barnes (barnes7td)
on 2010-11-09 17:46
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!
Posted by Tomas Matousek (Guest)
on 2010-11-09 20:02
(Received via mailing list)
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-...

Tomas
Posted by Andrius Bentkus (Guest)
on 2010-11-09 20:28
(Received via mailing list)
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/cl...,
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.
Posted by Timothy Barnes (barnes7td)
on 2010-11-09 20:34
Thanks for the help. I will see what I can do.

Timothy
Posted by Timothy Barnes (barnes7td)
on 2011-02-25 22:24
Attachment: win32ole_test.rb (5,66 KB)
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
Posted by Roger Pack (rogerdpack)
on 2011-03-11 18:35
> I don't  believe ruby allows you to create a class instance with out calling the 
new method.

maybe #allocate?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.