Have you tried creating a variant array and passing VT_ARRAY/VT_ARRAYREF?
Main Topics
Browse All TopicsI have an ADO Stream, opened in binary mode, and I want to write binary data to that stream. Below is a test program that compiles as a console application in VC++ 2008. It simply creates a new stream, opens it in binary mode, and attempts to write some data. Write() fails with error 0x800A0BB9 (invalid argument). I have no idea why.
If I open the stream in text mode and use WriteText, it works with no problem. If I open the stream in binary mode and use WriteText, it fails as expected (illegal operation). But, no matter what mode I open the stream in, when I use Write, it fails.
I have tried other VARIANT types besides the one in the code snippet below (arrays, other simple types), all with the same results. (In my actual program, I'm attempting to write an array of bytes as a SAFEARRAY wrapped in a VARIANT).
I've also tried setting the stream mode before opening it, with no effect. I have verified that the stream is open in binary mode by getting it's type and checking that it is adTypeBinary.
What am I doing wrong here? Why is Write failing every time? How do I write binary data to an ADO Stream?
In case you are wondering, the reason I am doing this is because I'm using CDOSYS to send emails with attachments, and I'm constructing attachments from blocks of arbitrary binary data in memory. The Stream in question is the decoded content stream from an IBodyPart. However, it seems to have nothing to do with CDOSYS, as I'm having the same problem in the test case below.
Thanks!
(Edit: Question rewritten -- it's pretty much the same as my first comment below now)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The Write method specifies that you pass it variant that is an array of bytes.
http://msdn.microsoft.com/
You are passing it a variant that is a single byte.
Note that Write does not accept a length parameter. To know how many bytes to write, it gets the length from the array variant.
@fredthered and DanRollins:
Thanks for your reply. Yes, I did try using an array. In fact, an array is what I intend to use, although the example I posted had the simpler types. I've attached code to this comment that uses a SAFEARRAY of bytes (VT_UI1). It makes no difference, and fails in exactly the same way (Write fails with 0x800A0BB9). It's very frustrating. What else could I be doing wrong?
@DanRollins: Thank you so much! I knew it had to be something strange like that, because I wasn't finding anybody else on the internet with a similar problem.
Turns out I had forgot to include VT_UI1 with VT_ARRAY in the VARIANT type in the original code, and I lost sight of that when I started using non-array types to test. Actually using the correct type fixed the problem (I tested it, in addition to Write succeeding, it does in fact work correctly).
This has been tripping me up for literally days. Thanks for helping me see the error! :-)
J
Business Accounts
Answer for Membership
by: JasonCiprianiPosted on 2009-09-19 at 14:31:32ID: 25374755
This may clear it up: Here is a test program that compiles as a console application in VC++ 2008. It simply creates a new stream, opens it in binary mode, and attempts to write some data. Write() fails with error 0x800A0BB9 (invalid argument). I have no idea why.
If I open the stream in text mode and use WriteText, it works with no problem. If I open the stream in binary mode and use WriteText, it fails as expected (illegal operation). No matter what mode I open the stream in, when I use Write, it fails.
I have tried other VARIANT types besides the one in the code snippet below (arrays, other simple types), all with the same results.
Select allOpen in new window