Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

IStream usage in .Net

I'm working on writing a Com object in .Net. Everything was going well until I had to write the Save functionality. I do this by using the IPersistStream interface which passes in an IStream interface pointer. Now, in C++, all I have to do is some funky casting to say, here's the address of the item I want to save and how big it is in bytes and the stream will go out and retrieve that place in memory and save them into the stream. But in C# things are not so nice: For the life of me I can't determine how to save something so simple as a long into the stream. The stream is expecting a byte (not a byte array as I expected), and any funky casting I do is thrown out because an lvalue is needed and I suppose that after a cast, it interprets the result as a rvalue. Has anyone ever tried to save simple data types into an IStream using C#. Any help is greatly appreciated. Thank you.

John Carlson
Wednesday, April 07, 2004

Don't know about IStreams specifically - but in .NET streams you wrap the base stream up in a BinaryWriter and Write(...) the values to it with that - you read them by wrapping a stream with a BinaryReader.

Basically the values need to be "serialised" by something first.

Another way of getting a bunch of bytes from a value is using System.Runtime.Serialization.Formatters.Binary.BinaryFormatter

HTH

Duncan Smart
Wednesday, April 07, 2004

If you are refering to the c++ unmanaged IStream you can convert a .net Managed Stream to an IStream by using the legacy adodb.dll.

Christopher C. Kane
Thursday, April 22, 2004

*  Recent Topics

*  Fog Creek Home