beautypg.com

Working with variants in visual c – Rockwell Automation FactoryTalk Historian Classic User Guide User Manual

Page 147

background image

Creating RSBizWare Custom Analysis Tools Chapter 7

Visual C++ supports the VARIANT data type, but VARIANTs are
not handled as elegantly in Visual C++ as they are in Visual Basic.
When RSBizWare is installed, a set of C++ source code files that
contain utility functions are also installed. In the Variant.cpp file,
there are functions that are useful when handling VARIANT data
types. These files are installed in the \Program Files\Rockwell
Software\RSBizWare\RSBizWare Calculators\C++\utility
directory.

To use these VARIANT functions in your program, do the
following:

1. Copy the Variant.h and Variant.cpp files from the utility

directory (\Program Files\Rockwell
Software\RSBizWare\RSBizWare Calculators\C++\Utility,
by default) to your project's source directory.

2. Add the Variant.cpp file to your project's Source Files (by

right-clicking the Source Files folder, selecting Add Files to
Folder from the shortcut menu, and selecting the file).

3. Include Variant.h before the class definition in the

NegativeCalc.h header file (by adding an

#include

“Variant.h”

statement to the NegativeCalc.h header file).

An excerpt of the Variant.h include file is listed below that describes
the utility functions implemented in the Variant.cpp file.

// Returns TRUE if a VARIANT has a type of VT_ARRAY|R8

// (array of doubles).

bool IsVariantDoubleArray(VARIANT *varray);

// Returns the number of elements in the array contained in a //
VARIANT.

long GetVariantDoubleArraySize(VARIANT *varray);

// Converts a VARIANT 1-dimensional SafeArray of doubles to a

// non-variant double array.

bool ExtractVariantDoubleArray(VARIANT *varray, double *vals,

int sizeVals, int *numVals);

// Converts a non-variant double array to a VARIANT 1-

// dimensional SafeArray of doubles

void CreateVariantDoubleArray(double *vals, int numVals,

Working with VARIANTs in
Visual C++

Rockwell Automation Publication HIST-UM001K-EN-E-June 2014

147