Tuesday, 8 July 2008

DotNet Stream to IStream

Lately I have been grafting some new cloth on to our legacy code. In this case, that means writing C# COM servers that get called from legacy Delphi.Win32 code.

I have been taking the various files that together comprise a user's model of the process flow in their organization and bundling them together using System.IO.Packaging (a nice wrapper on a ZIP file).

In all the places in the legacy Delphi code where it might try to get a TFileStream (Delphi people like to start their class names with the letter T) it will instead be getting a TOleStream on a C# object that implements IStream.

Here's the kicker. C# Stream objects don't implement IStream so you need a wrapper. Blech. Luckily for me, Oliver Sturm has already posted a partial solution (it implements Read but not Write) here so I was spared too much grief. Then it was just a matter of regenerating the Delphi wrappers for the assembly and now we're as good as gold, as they say in this country.

No comments: