John Lam 1997 — 2026

Windows Forms and Value Types

Justin in my comments reported not being able to create a simple MessageBox.Show('Hello, World') app. There were two things missing in Justin’s app: explicitly loading the System.Windows.Forms assembly, along with a bit of confusion about Ruby namespaces and scoping.

Here’s a version of Justin’s code that should work:

require 'rubyclr'
include RubyClr

RubyClr::reference 'System.Windows.Forms'

include System
include System::Windows::Forms

MessageBox.Show('Hello, World')

It displays the message box and then promptly crashes. Why? Because MessageBox.Show returns a DialogResult, which is a user-defined value type. I’m not marshaling user-defined value types yet, but it’s a very high priority for the next release of the bridge.

In other news, I’ve done some pretty major refactoring of the C++ code in my current internal builds – I was very unhappy with some of the code that I had in my first drop (hint: grep for ‘enema’ in the source). I’ve also got support for virtual call optimization in the current internal build.

I’m pretty busy writing ObjectSharp’s ASP.NET 2.0 Best Practices course the next couple of weeks, so I’m anticipating a new release of the bridge towards the end of next week. At the very least expect to see user defined value type marshaling working by then.

1 archived reader comment

Justin (2006-01-18)

Thanks for the post. I’ll wait until the next drop to play with it again. Installing .NET 2.0 side-by-side with 1.1 didn’t work out too well for me - but it was cool to see all the unit tests pass :)