.NET dll in Ruby

P

Patrick Spence

I have a "COM enabled" C# .NET .dll. I need to instanciate it in some
Ruby code. Has anyone done something like this? If so, how? It doesn't
seem to be as straight forward as a VB6 COM .dll.
 
S

Sam Smoot

Patrick said:
I have a "COM enabled" C# .NET .dll. I need to instanciate it in some
Ruby code. Has anyone done something like this? If so, how? It doesn't
seem to be as straight forward as a VB6 COM .dll.

I've used WIN32OLE with .NET COM wrappers just fine...

regasm /tlb /codebase mywrapper.dll

obj = WIN32OLE.new 'MyWrapper.AwesomeObject'
obj.DoSomethingReallyCool()

For a RubyClr example:

require 'rubyclr'
reference 'System'

include System

sb = Text::StringBuilder.new
sb.append 'This '
sb.append 'is '
sb.append 'how '
sb.append 'it\'s '
sb.append 'done'

"This is how it's done" == sb.to_string
 
W

William Crawford

unknown said:

The second one at least has an example, but the first one... There's 1
forum post and 1 bug in the tracker. That's not really my idea of
'information' on a project as big as making a new language work on the
NET CLR.

Even the most basic information is missing, like: What version of Ruby
does this equate to? What is and isn't implemented?

I assume it won't run ruby gems... But I don't know that, because
there's no information.
 
P

Patrick Spence

Sam said:
I've used WIN32OLE with .NET COM wrappers just fine...

regasm /tlb /codebase mywrapper.dll

obj = WIN32OLE.new 'MyWrapper.AwesomeObject'
obj.DoSomethingReallyCool()

Ok, I've got that working, well, sort of... The class has several public
properties and one public method. The only methods that show up via any
of the "ole_*" methods, are the IDispatch methods; QueryInterface,
AddRef, Release, etc.. Interestingly enough, however, I am able to
assign a value to one of the public properties w/o Ruby choking. Is
there some reason they don't show up?
 
B

brabuhr

Also some information at:(looks like the tag isn't very useful, better to search for RubyCLR)
The second one at least has an example, but the first one... There's 1
forum post and 1 bug in the tracker. That's not really my idea of
'information' on a project as big as making a new language work on the
.NET CLR.

Consider 'some' as my propensity for understatement :) It's not really
running Ruby on the CLR (like, for example Ruby.NET); it's an extension
module for Ruby 1.8 Win32 (I don't know if anyone has tested with
anything other than the One-Click Installer) to work with .NET objects
from Ruby. (I think that one of his prime motivations in writing this was
to use the .NET user-interface features he wanted while the logic driving
the interface stayed in elegant Ruby.)

http://rubyforge.org/plugins/scmsvn/viewcvs.php/trunk/README.TXT?root=rubyclr&view=markup
http://rubyforge.org/plugins/scmsvn/viewcvs.php/trunk/Samples/?root=rubyclr

Something like:

require 'rubyclr'
RubyClr::reference 'System'
System::Console.WriteLine("Hello")

I've used it from Rails to work with model data from a proprietary data store.
 
D

David Vallner

Patrick said:
Has anyone done something like this? If so, how? It doesn't
seem to be as straight forward as a VB6 COM .dll.

Amusingly enough:

irb(main):001:0> require 'win32ole'
=> true
irb(main):002:0> lst = WIN32OLE.new("System.Collections.ArrayList")
=> #<WIN32OLE:0x5f41780>
irb(main):003:0> lst.add('foo')
=> 0
irb(main):004:0> lst.add('bar')
=> 1
irb(main):005:0> lst.add('baz')
=> 2
irb(main):006:0> lst.Count
=> 3
irb(main):007:0> lst.Item(0)
=> "foo"
irb(main):008:0> lst.Item(1)
=> "bar"
irb(main):009:0> lst.Item(2)
=> "baz"

sans rubyclr. Maybe there's a problem with your DLL or its
COM-enabledness? Of course I just might have stumbled on a
System.Collections.ArrayList that is pre-.NET - I'm not too COM-savvy.

David Vallner
 
J

John Lam

I would suggest that you:

a) download RubyCLR - it runs on both 1.8.2 and 1.8.4
b) look at the unit tests - you'll find test cases that cover
virtually all scenarios
c) look at the sample applications - there are many, many sample
applications that cover a lot of the common scenarios (like
databinding ActiveRecord objects to data aware controls).
d) Google is your friend - read my blog entries and you'll see the
entire history of RubyCLR's implementation laid out.

If you have specific questions, feel free to post back here.

-John
http://www.iunknown.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top