As we progressed with CLR interop for Bee Smalltalk, a need to create a delegate for an unmanaged code arose. By “a delegate for an unmanaged code” I mean an instance of a delegate object that can be passed to CLR code which, when called, would execute an unmanaged code. In our case a Smalltalk code.
This can be handy, maybe necessary, if we want write a code that handles events. And we may well would like to do so, writing some UI code using .NET classes without use of event handlers seems to be impossible. Moreover, there are other interesting events we may want to handle, such as AppDomain.FirstChanceException.
Looking at the .NET documentation. this seem to be an easy task. Just use Marshal.GetDelegateForFunctionPointer() to create a delegate object for an arbitrary function pointer. Looks easy but it turned out to be a little more tricky. And not very well documented. The following text describes my findings and my solution so far. Mainly for my (our) own record but someone else may find useful too.
While working on CLR interop for Bee Smalltalk, things go wrong every now and again. This is tricky to debug, at least for me, as there is Smalltalk code, then some native C++ code (CLR’s CCW and all this stuff) and finally managed CLR code.
Obviously, Smalltalk debugger is kind of useless here as one would not see native nor managed stack there. Managed debugger is can be useful to see what’s happening in managed code, but quite often it got confused because we’re calling CLR from native application so more often than not all it tells you is that something went wrong - in case you don’t know that yet.
Couple days ago, I finally managed to get .NET to do a job for me. Not much but still .NET did its job and did it well. The following text shows how to call .NET code from Bee Smalltalk and retrieve results. I won’t go into technical details on how it’s done internally, rather show the usage from user point of view. The goal is to give you an idea how it might feel to call .NET code from Bee Smalltalk.
Couple weeks ago I decided to make myself a small home server. Home sever, sounds weird, doesn’t it? Home’s not work place, no?
Well, it is, in my case. I have no need for media center, downloading and streaming movies or even playing on TV, nothing like this. But I need a storage for backups and host to run virtual machines on.
There is no programming language that rules them all.
I'm interested in programming languages, compilers and virtual machines, in particular in multi-language programming environments.
I love Smalltalk. But I'm critical about it, all the same.