COM Classes and Data Types for C

COM Classes and Data Types for C++

This is a brief list of the nonnative C++ COM data types and helper classes you are likely to have to deal with when using MSXML.

  • VARIANT, encapsulated as a COM helper class in C++ as _variant_t : This data type is the most awkward . It's a structure with several fields. The first one is a VARTYPE that specifies the type of VARIANT, that is, the data type of the data stored in the VARIANT. The last one is a union of several field types that contains the value of the VARIANT. There are only a few DOM methods that use a VARIANT, and for each I show how to set up the VARIANT.

  • BSTR Binary String data type, encapsulated as a COM helper class in C++ as _bstr_t : COM uses this in several places, but we mostly use it to represent character data in a VARIANT. A BSTR can be cast as TEXT, TCHAR, and LPTSTR to handle character sets other than the default. To keep things simple, we'll just use the BSTR whenever possible. Visual C++ usually is perfectly happy treating a _bstr_t as a char *.

VARIANT in the MSXML DOM Implementation

We most often have to deal with the VARIANT data type in the DOM get and set NodeValue methods. In the W3C DOM Recommendation these have different return and argument values depending on the Node type. For example, getNodeValue on a Text Node returns the text associated with the parent Element. When called on a Processing Instruction Node it returns the entire content excluding the target. When called on almost anything else it returns a NULL. From the perspective of someone developing a DOM API, using a VARIANT is a perfectly logical choice. However, it doesn't make life very easy for someone using the API. Java's JAXP is much easier to use in this regard, and so is the DOM implementation in System.XML in .NET.

If you find something in the book's code or in the MSXML sample code that isn't listed here, you can usually learn more about it by performing an index or search in the MSDN Library (available online at or from online help in Visual Studio).

Using XML with Legacy Business Applications
Using XML with Legacy Business Applications
ISBN: 0321154940
EAN: 2147483647
Year: 2003
Pages: 181

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: