Export (0) Print
Expand All
Expand Minimize

VariantUse Sample: Demonstrates the Use of Variants

The VariantUse sample demonstrates changing existing data into a variant, and changing a variant into other types of data. Many COM objects accept variants as function parameters. The goal of this sample is to help you change standard C data types into variants.

This sample covers the use of currency, dates, SAFEARRAYs, multidimensional arrays, strings, chars, shorts, and longs.

Building and Running the Sample

To build and run the VariantUse sample

  1. Open the solution VariantUse.sln.
  2. On the Build menu, click Build.

Run VariantUse.exe in the debugger. Place breakpoints in the code dealing with the type of data you are trying to understand. For example, if you want to see the use of variants with strings, place breakpoints in the OnString function. Run the sample in the debugger and click the Strings button. Clicking the buttons on the main dialog box will have no apparent effect unless there are breakpoints in the associated code. Once a breakpoint is reached, use the debugger's single-step feature to step through the code that transforms data into and out of a variant.

Keywords

This sample uses the following keywords:

_bstr_t; CComBSTR; CComBSTR::Append; COleSafeArray; COeSafeArray::AccessData; COleSafeArray::CreateOneDim; COleSafeArray::UnaccessData; CString; CURRENCY; SAFEARRAY; SafeArrayAccessData; SAFEARRAYBOUND; SafeArrayCreate; SafeArrayCreateVector; SafeArrayDestroy; SafeArrayGetElement; SafeArrayUnaccessData; SysAllocString; SysFreeString; T2COLE; USES_CONVERSION; VARIANT; VariantChangeType; VariantCopy

Note   Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

MFC Samples

Show:
© 2014 Microsoft