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.)

Leave a Reply

Your email address will not be published. Required fields are marked *