Variant Streaming Code

.

Overview

This code provides two global functions, WriteVariantToStream and ReadVariantFromStream, that enable you to read and write a variant to a stream. In addition, there are two other global functions, ReadVariantFromBlob and WriteVariantToBlob, for reading and writing a variant to a BLOB.

Highlights

Here are some of the main advantages of these functions:
  • Uses any given IStream to stream the Variant into and out of.
  • Data is streamed in efficient binary form.
  • Stream is versioned for backwards compatibility.
  • Supports arbitrary size and arbitrary dimension safe-arrays.
  • Object streaming is supported if the object in variant supports IPersistStream[Init].
  • All code is in one header file (VariantStream.h) and only two routines are exposed: WriteVariantToStream and ReadVariantFromStream.
  • Comes with supporting test code that tests the header file -- in case code is modified
  • Does not use C++ exception handling.  Test project has EH flag turned..
  • Doesn't use the CRT.
  • Does not use any Direct-To-COM (VC++'s comdef.h, such as _variant_t, _bstr_t, _com_ptr, _com_error)
  • Works in both Unicode and ANSI

Downloads

Download source - 37 Kb


Comments

  • There may be a way to do this using VARIANT_UserMarshal, VARIANT_UserUnmarshal

    Posted by kasajian on 01/14/2010 05:14pm

    It may be possible to do this using these functions: VARIANT_UserMarshal VARIANT_UserUnmarshal

    Reply
  • The hope page for this code

    Posted by kasajian on 08/23/2007 12:31pm

    http://kasajian.com/VariantStream.html

    Reply
  • Excellent!

    Posted by Legacy on 01/09/2003 12:00am

    Originally posted by: Greg Holt

    Very well thought out code. Very clean and easy to understand. I don't understand why Microsoft doesn't provide this functionality.

    Only enhancement that I would like to see (and will probably end up writing it myself) is the ability to use BLOB data instead of an IStream. I know that you can use StreamToTaskMemory and BlobToStream but I don't want the overhead of having to always create a Stream everytime I want to write/read a variant.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds