.NET dll in Ruby

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.

···

--
Posted via http://www.ruby-forum.com/.

Have you looked at RubyCLR (http://www.rubyclr.com)?

···

On 8/25/06, Patrick Spence <patrick@pkspence.com> wrote:

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.

Patrick Spence wrote:

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.

--
Posted via http://www.ruby-forum.com/\.

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

Patrick Spence wrote:

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

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

···

On 8/25/06, Patrick Spence <patrick@pkspence.com> wrote:

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.

--
Posted via http://www.ruby-forum.com/\.

unknown wrote:

···

On 8/25/06, Patrick Spence <patrick@pkspence.com> wrote:

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.

Have you looked at RubyCLR (http://www.rubyclr.com)?

As someone who has programmed in C#, this appeals to me. Too bad
there's almost no information on the project there.

--
Posted via http://www.ruby-forum.com/\.

Sam Smoot wrote:

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?

···

--
Posted via http://www.ruby-forum.com/\.

Also some information at:
    http://rubyforge.org/projects/rubyclr/
    http://www.iunknown.com/articles/tag/rubyclr

···

On 8/25/06, Patrick Spence <patrick@pkspence.com> wrote:

>> 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.
>
> Have you looked at RubyCLR (http://www.rubyclr.com)?

On 8/25/06, William Crawford <wccrawford@gmail.com> wrote:

As someone who has programmed in C#, this appeals to me. Too bad
there's almost no information on the project there.

unknown wrote:

>> 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.
>
> Have you looked at RubyCLR (http://www.rubyclr.com)?

As someone who has programmed in C#, this appeals to me. Too bad
there's almost no information on the project there.

Also some information at:
    http://rubyforge.org/projects/rubyclr/
    http://www.iunknown.com/articles/tag/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.

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.

···

On 8/25/06, Patrick Spence <patrick@pkspence.com> wrote:
On 8/25/06, William Crawford <wccrawford@gmail.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

> Also some information at:
> http://rubyforge.org/projects/rubyclr/
> http://www.iunknown.com/articles/tag/rubyclr

(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 :slight_smile: 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.