Mar 21, 2015

Some COM for you - Chapter 1

In which Piglet Meets a Heffalump Delphi meets .Net

"I saw one once," said Piglet. "At least, I think I did," he said. "Only perhaps it wasn't."
A. A. Milne

If you ever programmed for Windows, you should have heard weird stories of evil COM that lurks there in shadows waiting to drag you into the abyss of marshalling and IUnknowns...

As for me, I remembered Joel saying that when Microsoft first presented COM, they were proud to say that "it requires at least 20 000 lines of code just to get started". (Strangely, I can't find that line on his site anymore, can somebody help me with it?) So I never had any will to learn COM through (which may be not the best part of me), but anyway.

When I found that I need to use some COM libraries in a desktop app I decided to study C# because .Net has been said to have native COM support and I should not have to worry about the details. (And this was for the better, actually! I was prejudiced against C# knowing that Gosling blamed it for having unsafe code, but it turned out that C# is actually a better Java, and I like it!).

So when I recently found that I have to make a C# library to work with Delphi app and the only way to do it is COM, I started preparing for worst. Below is a story of how to make this work, which I'd like to keep in case I'll need to do something like that again.

The problem just reminded me about this promising energy source