ADODB.Stream into byte array

  • Thread starter Thread starter Guest
  • Start date Start date
There really isn't a direct way to do this. The only workaround I see
is to call the SaveToFile method on the stream, and then read the bytes from
the file.

You might try and cast the Stream object to an IPersistMemory interface
instance (it is a COM interface, you might have to define it if it isn't
already defined somewhere). If that works, then you can write the contents
directly to a byte array. Either that, or the IStream COM interface (at
which point, you could read characters from the stream, and then write them
to your byte array).

Hope this helps.
 
Nicholas, thank you for your reply.

I've used IStream. I'm getting a byte array and can work with it. This is
my code:

IStream iStream = (IStream)adodbStream;
byte[] byteArray = new byte[adodbStream.Size];
IntPtr ptrCharsRead = IntPtr.Zero;
iStream.Read(byteArray, adodbStream.Size, ptrCharsRead);

I fudged this. I'm not sure what the IntPtr business is. The documentation
says "ptrCharsRead" is a pointer to a ULONG variable that receives the actual
number of bytes read from the stream object.

How do I print the value of the ULONG variable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top