Using _bstr_t and _variant_t Classes

One of the more tedious jobs when using ADOCE is packaging data into VARIANT structures to be passed to methods and properties. Much of this data uses the BSTR data type. You will need to keep track of the creation of BSTR variables and remember to destroy them. To make life easier, you can use the _bstr_t and _variant_t classes, support for which is provided directly bythe C++ compiler. For example, if you need to create a VARIANT variable that contains a BSTR initialized and allocated with a string, you can write the following:

_bstr_t bstrVal(_T("Data Value"));
_variant_t varVal(bstrVal);

In this case, a BSTR is created, initialized with the string 'Data Value', and managed by the _bstr_t. A VARIANT

Get Windows® CE 3.0 Application Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.