Joe White’s Blog

Life, .NET, and Cats


Calling .NET code, and hooking events, from Delphi/Win32

A while back, my colleague Sam blogged about our experiences with using a .NET library from Win32. We wound up having to write glue code in managed C++. I recently had occasion to want to link to all three of his posts at once, so here they are.

  1. Exposing .NET code in a DLL via C++
  2. Calling into the C++ DLL from Delphi
  3. Hooking up a Delphi progress event to a .NET object

Note that this code is pretty hairy, but it’s also pretty formulaic. It’s absurd how much code it takes to hook one .NET event from Win32, but if you don’t need events, it’s merely unpleasant.

(Yes, we know about Hydra, but it’s not polished enough for us yet. For example, the way it marshals a Win32 exception into .NET is different from the way it marshals a .NET exception into Win32; one way (I don’t remember which) works great, but the other direction just gets you something like an “External exception” and you lose your original exception message. We haven’t needed it badly enough yet to want to figure out, and work around, all its quirks.)

There are no responses to “Calling .NET code, and hooking events, from Delphi/Win32” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2008. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS).