Using _bstr_t and _variant_t Classes

< BACK  NEXT >
[oR]

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 variable is created, and the _variant_t class constructor initializes the VARIANT's vt member with VT_BSTR. The BSTR union member pbstrVal can be used to access the value. The _variant_t class has a number of different constructors and copy constructors that allow values to be set into the VARIANT and the vt member automatically set with the correct data type indicator. The BSTR will be de-allocated correctly when the variables go out of scope. You will see examples of how to use these two classes in subsequent code samples.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net