Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

VarPacker DLL

VC++ Data Type Wrapping Library

Function Reference
@Copyright 1998~2001 ADLINK Technology Inc.
All Rights Reserved.
Manual Rev: 2.30: November 15, 2001
The information in this document is subject to change without prior notice in order to improve reliability, design
and function and does not represent a commitment on the part of the manufacturer.
In no event will the manufacturer be liable for direct, indirect, special, incidental, or consequential damages
arising out of the use or inability to use the product or documentation, even if advised of the possibility of such
damages.
This document contains proprietary information protected by copyright. All rights are reserved. No part of this
manual may be reproduced by any mechanical, electronic, or other means in any form without prior written
permission of the manufacturer.
Getting Service from ADLINK
♦ Customer Satisfaction is always the most important thing for ADLINK Tech Inc. If you need any help
or service, please contact us and get it.

ADLINK Technology Inc.


Web Site http://www.adlink.com.tw
http://www.adlinktechnology.com
Sales & service@adlink.com.tw
Service
Technical NuDAQ nudaq@adlink.com.tw
Support NuDAM nudam@adlink.com.tw
NuIPC nuipc@adlink.com.tw
NuPRO nupro@adlink.com.tw
Software sw@adlink.com.tw
AMB amb@adlink.com.tw
TEL +886-2-82265877 FAX +886-2-82265717
Address 9F, No. 166, Jian Yi Road, Chungho City, Taipei, 235 Taiwan,
R.O.C.
♦ Please inform or FAX us of your detailed information for a prompt, satisfactory and constant service.

Detailed Company Information


Company/Organizati
on
Contact Person
E-mail Address
Address
Country
TEL FAX
Web Site
Questions
Product Model
Environment to Use ¨OS:
¨Computer Brand:
¨M/B: ¨CPU:
¨Chipset: ¨Bios:
¨Video Card:
¨Network Interface Card:
¨Other:

Challenge
Description

Suggestions for
ADLINK
Table of Contents
Simple Data Type to VARIANT Functions ...........................................2
BoolToVar..........................................................................................................2
CharToVar..........................................................................................................2
ShortToVar .........................................................................................................2
LongToVar .........................................................................................................3
FloatToVar..........................................................................................................3
DoubleToVar ......................................................................................................3
VARIANT to Simple Data Type Functions ...........................................3
VarToBool ..........................................................................................................3
VarToChar ..........................................................................................................4
VarToShort .........................................................................................................4
VarToLong .........................................................................................................4
VarToFloat..........................................................................................................5
VarToDouble ......................................................................................................5
VARIANT to Array Data Functions .....................................................5
VarToArray ........................................................................................................5
VarToArray ........................................................................................................6
VarToArray ........................................................................................................7
VarToArray ........................................................................................................8
VarToArray ........................................................................................................8
Array Data to VARIANT Classes..........................................................9
VarPacker is a function library and class library help user wrap the simple type
variables in the VARIANT structure. In VC++ environment, some motheds of
DAQBench controls need user to pass parameter in a VARIANT structure. Althrough
MFC provides some classes to do that, such as COleVariant, COleSafeArray and so on,
but it only support simple data type and is not suitable for the usage in DAQBench.
Hence, DAQBench provide the VarPacker.dll to provide a more easy way for passing
parameters in DAQBench.
In the VarPacker.dll, it provid 4 groups of APIs :
1. Simple data type to VARIANT
2. VARIANT to simple data type
3. VARIANT to array data
4. Array data to VARIANT
The first three parts are in the function form, comparatively the last one part are in the
class form. The detail description of these function are described as below :

1
Simple Data Type to VARIANT Functions
VARIANT BoolToVar(bool Data)
Syntax
BoolToVar(boolVal);
Return Value
VARIANT that wrap the bool type data
Argument
boolVal: a bool type data
Remark

Call this function to wrap a bool type variable in a VARIANT structure.

VARIANT CharToVar(unsigned char Data)


Syntax
CharToVar(charVal);
Return Value
VARIANT that wrap the unsigned char type data
Argument
charVal : a unsigned char type data
Remark
Call this function to wrap a unsigned char type variable in a VARIANT structure.
For wrapping char type data, please cast the char argument as unsigned char before
passing.

VARIANT ShortToVar(short Data)


Syntax
ShortToVar(shortVal);
Return Value
VARIANT that wrap the short type data
Argument
shortVal : a short type data
Remark
Call this function to wrap a short type variable in a VARIANT structure. For
wrapping unsigned short type data, please cast the unsigned short argument as
short before passing.

2
VARIANT LongToVar(long Data)
Syntax
LongToVar(longVal);
Return Value
VARIANT that wrap the long type data
Argument
longVal : a long type data
Remark
Call this function to wrap a long type variable in a VARIANT structure. For
wrapping unsigned long type data, please cast the unsigned long argument as long
before passing.

VARIANT FloatToVar(unsigned char Data)


Syntax
FloatToVar(floatVal);
Return Value
VARIANT that wrap the float type data
Argument
floatVal : a float type data
Remark
Call this function to wrap a float type variable in a VARIANT structure.

VARIANT DoubleToVar(double Data)


Syntax
DoubleToVar(doubleVal);
Return Value
VARIANT that wrap the double type data
Argument
doubleVal : a double type data
Remark
Call this function to wrap a double type variable in a VARIANT structure.

VARIANT to Simple Data Type Functions


Bool VarToBool(const VARIANT& var)
Syntax
Bool boolVal;
VARIANT variantVal;

3
boolVal=VarToBool(variantVal);
Return Value
Bool value wrapped in the VARIANT structure
Argument
VariantVal; the reference of the VARIANT variable
Remark
Call this function to extract the Bool value wrapped in a VARIANT structure.

unsigned char VarToChar(const VARIANT& var)


Syntax
unsgined char charVal;
VARIANT variantVal;
charVal=VarToChar(variantVal);
Return Value
unsigned char value wrapped in the VARIANT structure
Argument
variantVal the reference of the VARIANT variable
Remark
Call this function to extract the unsigned char value wrapped in a VARIANT
structure.

short VarToShort(const VARIANT& var)


Syntax
short shortVal;
VARIANT variantVal;
shortVal=VarToShort(variantVal);
Return Value
short value wrapped in the VARIANT structure
Argument
VariantVal : the reference of the VARIANT variable
Remark
Call this function to extract the short value wrapped in a VARIANT structure.

long VarToLong(const VARIANT& var)


Syntax
long shortVal;
VARIANT variantVal;
longVal=VarToLong(variantVal);

4
Return Value
long value wrapped in the VARIANT structure
Argument
variantVal: the reference of the VARIANT variable
Remark
Call this function to extract the long value wrapped in a VARIANT structure.

float VarToFloat(const VARIANT& var)


Syntax
float shortVal;
VARIANT variantVal;
floatVal=VarToFloat(variantVal);
Return Value
float value wrapped in the VARIANT structure
Argument
VariantVal : the reference of the VARIANT variable
Remark
Call this function to extract the float value wrapped in a VARIANT structure.

double VarToDouble(const VARIANT& var)


Syntax
double shortVal;
VARIANT variantVal;
doubleVal=VarToDouble(variantVal);
Return Value
double value wrapped in the VARIANT structure
Argument
variantVal: the reference of the VARIANT variable
Remark
Call this function to extract the double value wrapped in a VARIANT structure.

VARIANT to Array Data Functions


short VarToArray(const VARIANT var, unsigned char* pArray,
unsigned int DataLength)
Syntax
VARIANT var;
unsigned char charArray[100];

5
short retVal;
//Get an array that wrapped in var
retVal= VarToArray (var, charArray, 100);
Return Value
If succeeded, return the number of elements extracted to the data array. If failed,
return the follow error codes:
ERR_NO_ARRAY_IN_VARIANT : Indicates that there is no array wrapped in
the VARIANT structure, or the memory space of wrapped array is not accessible.
ERR_ARRAY_TYPE_MISMATCH :Indicates that the type of wrapped array is
different from the type of the given data array.
ERR_ARRAY_SPACE_ACCESS_ERR : Indicates that the memeory space of the
given data array is not accessible.
Argument
Var: the reference of the VARIANT variable
pArray: the pointer of array where you want to place the extracted data
DataLength: the number of elements you want to extract from VARIANT
Remark
Call this function to extract the wrapped unsigned char array from a VARIANT
structure to a given unsigned char array.
The DataLength argument must not be larger that the size you declare for pArray,
or memory access violation may occur.
While no wrapped array is in the VARAINT or the type of wrapped array is not
unsigned char, error code returns.

short VarToArray(const VARIANT var, short* pArray, unsigned int


DataLength)
Syntax
VARIANT var;
short shortArray[100];
short retVal;
//Get an array that wrapped in var
retVal= VarToArray (var, shortArray, 100);
Return Value
If succeeded, return the number of elements extracted to the data array
If failed, return the follow error codes:
ERR_NO_ARRAY_IN_VARIANT : Indicates that there is no array wrapped in
the VARIANT structure, or the memory space of wrapped array is not accessible.
ERR_ARRAY_TYPE_MISMATCH : Indicates that the type of wrapped array is

6
different from the type of the given data array.
ERR_ARRAY_SPACE_ACCESS_ERR : Indicates that the memeory space of the
given data array is not accessible.
Argument
Var: the reference of the VARIANT variable
pArray: the pointer of array where you want to place the extracted data
DataLength: the number of elements you want to extract from VARIANT
Remark
Call this function to extract the wrapped unsigned char array from a VARIANT
structure to a given unsigned char array.
The DataLength argument must not be larger that the size you declare for pArray,
or memory access violation may occur.
While no wrapped array is in the VARAINT or the type of wrapped array is not
short, error code returns.

short VarToArray(const VARIANT var, long* pArray, unsigned int


DataLength)
Syntax
VARIANT var;
long longArray[100];
short retVal;
//Get an array that wrapped in var
retVal= VarToArray (var, longArray, 100);
Return Value
If succeeded, return the number of elements extracted to the data array
If failed, return the follow error codes:
ERR_NO_ARRAY_IN_VARIANT : Indicates that there is no array wrapped in
the VARIANT structure, or the memory space of wrapped array is not accessible.
ERR_ARRAY_TYPE_MISMATCH : Indicates that the type of wrapped array is
different from the type of the given data array.
ERR_ARRAY_SPACE_ACCESS_ERR : Indicates that the memeory space of the
given data array is not accessible.
Argument
Var: the reference of the VARIANT variable
pArray: the pointer of array where you want to place the extracted data
DataLength: the number of elements you want to extract from VARIANT
Remark
Call this function to extract the wrapped unsigned char array from a VARIANT

7
structure to a given unsigned char array.
The DataLength argument must not be larger that the size you declare for pArray,
or memory access violation may occur.
While no wrapped array is in the VARAINT or the type of wrapped array is not
long, error code returns.

short VarToArray(const VARIANT var, float* pArray, unsigned int


DataLength)
Syntax
VARIANT var;
float floatArray[100];
short retVal;
//Get an array that wrapped in var
retVal= VarToArray (var, floatArray, 100);
Return Value
If succeeded, return the number of elements extracted to the data array
If failed, return the follow error codes:
ERR_NO_ARRAY_IN_VARIANT : Indicates that there is no array wrapped in
the VARIANT structure, or the memory space of wrapped array is not accessible.
ERR_ARRAY_TYPE_MISMATCH : Indicates that the type of wrapped array is
different from the type of the given data array.
ERR_ARRAY_SPACE_ACCESS_ERR : Indicates that the memeory space of the
given data array is not accessible.
Argument
Var: the reference of the VARIANT variable
pArray: the pointer of array where you want to place the extracted data
DataLength: the number of elements you want to extract from VARIANT
Remark
Call this function to extract the wrapped unsigned char array from a VARIANT
structure to a given unsigned char array.
The DataLength argument must not be larger that the size you declare for pArray,
or memory access violation may occur.
While no wrapped array is in the VARAINT or the type of wrapped array is not
float, error code returns.

short VarToArray(const VARIANT var, double* pArray, unsigned int


DataLength)
Syntax

8
VARIANT var;
double doubleArray[100];
short retVal;
//Get an array that wrapped in var
retVal= VarToArray (var, doubleArray, 100);
Return Value
If succeeded, return the number of elements extracted to the data array
If failed, return the follow error codes:
ERR_NO_ARRAY_IN_VARIANT : Indicates that there is no array wrapped in
the VARIANT structure, or the memory space of wrapped array is not accessible.
ERR_ARRAY_TYPE_MISMATCH : Indicates that the type of wrapped array is
different from the type of the given data array.
ERR_ARRAY_SPACE_ACCESS_ERR : Indicates that the memeory space of the
given data array is not accessible.
Argument
Var: the reference of the VARIANT variable
pArray: the pointer of array where you want to place the extracted data
DataLength: the number of elements you want to extract from VARIANT
Remark
Call this function to extract the wrapped unsigned char array from a VARIANT
structure to a given unsigned char array.
The DataLength argument must not be larger that the size you declare for pArray,
or memory access violation may occur.
While no wrapped array is in the VARAINT or the type of wrapped array is not
double, error code returns.

Array Data to VARIANT Classes


ArrayToVar Class:
The ArrayToVar class to help user to wrap a 1-dimension array in the VARIANT
structure. The polymorphism feature in C++ language provide users different class
constructor according to different arguments. This class is useful for the controls need
1-diemnsion array as its argument, such as DChart, DGraph, and DXYGraph.

class ArrayToVar : public tagVARIANT


{
public:

9
ArrayToVar(unsigned char* pData, int DataLength);
ArrayToVar(short* pData, int DataLength);
ArrayToVar(long* pData, int DataLength);
ArrayToVar(float* pData, int DataLength);
ArrayToVar(double* pData, int DataLength);
~ArrayToVar();
};

The member function of ArrayToVar Class :


ArrayToVar(unsigned char* pData, int DataLength)
Syntax
There are two ways to use the ArrayToVar class. You can:
unsigned char charArray[100];
// fill the value of elements in charArray
DChart.PlotChart(ArrayToVar(charArray, 100));
Or
unsigned char charArray[100];
// fill the value of elements in charArray
ArrayToVar var(charArray, 100);
DChart.PlotChart(var);
Argument
pData : the pointer of the array to be wrapped in a VARIANT structure
DataLength: number of elements of the array
Remark
Call this function to wrap the unsigned char array in a VARIANT structure.
The DataLength argument can be equal to or smaller than the actual size of the
array. DataLength greater than the actual size of array may cause memory access
violation.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=ArrayToVar(charArray, 100);
Please do not use ArrayToVar in this way to avoid error.

ArrayToVar(short* pData, int DataLength);


Syntax

10
There are two ways to use the ArrayToVar class. You can:
short shortArray[100];
// fill the value of elements in shortArray
DChart.PlotChart(ArrayToVar(shortArray, 100));
Or
short shortArray[100];
// fill the value of elements in shortArray
ArrayToVar var(shortArray, 100);
DChart.PlotChart(var);
Argument
pData : the pointer of the array to be wrapped in a VARIANT structure
DataLength: number of elements of the array
Remark
Call this function to wrap the short array in a VARIANT structure.
The DataLength argument can be equal to or smaller than the actual size of the
array. DataLength greater than the actual size of array may cause memory access
violation.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=ArrayToVar(shortArray, 100);
Please do not use ArrayToVar in this way to avoid error.

ArrayToVar(long* pData, int DataLength);


Syntax
There are two ways to use the ArrayToVar class. You can:
long longArray[100];
// fill the value of elements in longArray
DChart.PlotChart(ArrayToVar(longArray, 100));
Or
long longArray[100];
// fill the value of elements in longArray
ArrayToVar var(longArray, 100);
DChart.PlotChart(var);
Argument
pData : the pointer of the array to be wrapped in a VARIANT structure

11
DataLength: number of elements of the array
Remark
Call this function to wrap the short array in a VARIANT structure.
The DataLength argument can be equal to or smaller than the actual size of the
array. DataLength greater than the actual size of array may cause memory access
violation.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=ArrayToVar(longArray, 100);
Please do not use ArrayToVar in this way to avoid error.

ArrayToVar(float* pData, int DataLength);


Syntax
There are two ways to use the ArrayToVar class. You can:
float floatArray[100];
// fill the value of elements in floatArray
DChart.PlotChart(ArrayToVar(floatArray, 100));
Or
float floatArray[100];
// fill the value of elements in floatArray
ArrayToVar var(floatArray, 100);
DChart.PlotChart(var);
Argument
pData : the pointer of the array to be wrapped in a VARIANT structure
DataLength: number of elements of the array
Remark
Call this function to wrap the short array in a VARIANT structure.
The DataLength argument can be equal to or smaller than the actual size of the
array. DataLength greater than the actual size of array may cause memory access
violation.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than

12
VARAINT var=ArrayToVar(floatArray, 100);
Please do not use ArrayToVar in this way to avoid error.

ArrayToVar(double* pData, int DataLength);


Syntax
There are two ways to use the ArrayToVar class. You can:
double doubleArray[100];
// fill the value of elements in doubleArray
DChart.PlotChart(ArrayToVar(doubleArray, 100));
Or
double doubleArray[100];
// fill the value of elements in doubleArray
ArrayToVar var(doubleArray, 100);
DChart.PlotChart(var);
Argument
pData : the pointer of the array to be wrapped in a VARIANT structure
DataLength: number of elements of the array
Remark
Call this function to wrap the short array in a VARIANT structure.
The DataLength argument can be equal to or smaller than the actual size of the
array. DataLength greater than the actual size of array may cause memory access
violation.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=ArrayToVar(doubleArray, 100);
Please do not use ArrayToVar in this way to avoid error.

_2DimArrayToVar Class :
The _2DimArrayToVar class helps you to wrap a 2-Dimension array in the VARIANT
structure. We provide this class dedicatedly to DIntenChart and DintenGraph controls.
Because these two controls need (x, y) coordinate to plot z value, they need a
2-dimension array as argument. We also take the advantage of polymorphism in C++ to
provide overloading constructors.

class _2DimArrayToVar : public COleSafeArray

13
{
public:
_2DimArrayToVar(unsigned char* pData, int Dim1DataLength,
int Dim2DataLength);
_2DimArrayToVar(short* pData, int Dim1DataLength, int Dim2DataLength);
_2DimArrayToVar(long* pData, int Dim1DataLength, int Dim2DataLength);
_2DimArrayToVar(float* pData, int Dim1DataLength, int Dim2DataLength);
_2DimArrayToVar(double* pData, int Dim1DataLength, int Dim2DataLength);
~_2DimArrayToVar();
};

The member functions of _2DimArrayToVar Class :


_2DimArrayToVar(unsigned char* pData, int Dim1DataLength,
int Dim2DataLength);
Syntax
There are two ways to use the _2DimArrayToVar class. You can:
unsigned char zData[100][100];
// fill the value of elements in zData
DIntenChart.AddPlane(_2DimArrayToVar(zData, 100, 100));
Or
unsigned char zData[100][100];
// fill the value of elements in zData
_2DimArrayToVar var(zData, 100, 100);
DIntenChart.AddPlane(var);
Argument
pData : the pointer of the 2-dimension array to be wrapped in a VARIANT
structure
Dim1DataLength: number of elements of 1st dimension of the array
Dim2DataLength: number of elements of 2nd dimension of the array
Remark
Call this function to wrap the 2-dimension unsigned char array in a VARIANT
structure.
The Dim1DataLength and Dim2DataLength argument can be equal to or smaller
than the actual size you declare in the array. Dim1DataLength and
Dim2DataLength greater than the actual size of array may cause memory access
violation.
Remember that in VC++, you can not dynamically declare a 2-dim array. If you
want to do so, please use a dynamically allocated 1-dim array as the pData, and

14
still pass the Dim1DataLength and Dim2DataLength arguments (size of array
equals to Dim1DataLength* Dim2DataLength). You can view the IntenGraph
sample program for detail.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=_2DimArrayToVar(zData, 100, 100);
Please do not use ArrayToVar in this way to avoid error.

_2DimArrayToVar(short* pData, int Dim1DataLength, int Dim2DataLength);


Syntax
There are two ways to use the _2DimArrayToVar class. You can:
short zData[100][100];
// fill the value of elements in zData
DIntenChart.AddPlane(_2DimArrayToVar(zData, 100, 100));
Or
short zData[100][100];
// fill the value of elements in zData
_2DimArrayToVar var(zData, 100, 100);
DIntenChart.AddPlane(var);
Argument
pData : the pointer of the 2-dimension array to be wrapped in a VARIANT
structure
Dim1DataLength: number of elements of 1st dimension of the array
Dim2DataLength: number of elements of 2nd dimension of the array
Remark
Call this function to wrap the 2-dimension short array in a VARIANT structure.
The Dim1DataLength and Dim2DataLength argument can be equal to or smaller
than the actual size you declare in the array. Dim1DataLength and
Dim2DataLength greater than the actual size of array may cause memory access
violation. Remember that in VC++, you can not dynamically declare a 2-dim array.
If you want to do so, please use a dynamically allocated 1-dim array as the pData,
and still pass the Dim1DataLength and Dim2DataLength arguments (size of array
equals to Dim1DataLength* Dim2DataLength). You can view the IntenGraph
sample program for detail.
Caution

15
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=_2DimArrayToVar(zData, 100, 100);
Please do not use ArrayToVar in this way to avoid error.

_2DimArrayToVar(long* pData, int Dim1DataLength, int Dim2DataLength);


Syntax
There are two ways to use the _2DimArrayToVar class. You can:
long zData[100][100];
// fill the value of elements in zData
DIntenChart.AddPlane(_2DimArrayToVar(zData, 100, 100));
Or
long zData[100][100];
// fill the value of elements in zData
_2DimArrayToVar var(zData, 100, 100);
DIntenChart.AddPlane(var);
Argument
pData : the pointer of the 2-dimension array to be wrapped in a VARIANT
structure
Dim1DataLength: number of elements of 1st dimension of the array
Dim2DataLength: number of elements of 2nd dimension of the array
Remark
Call this function to wrap the 2-dimension long array in a VARIANT structure.
The Dim1DataLength and Dim2DataLength argument can be equal to or smaller
than the actual size you declare in the array. Dim1DataLength and
Dim2DataLength greater than the actual size of array may cause memory access
violation.Remember that in VC++, you can not dynamically declare a 2-dim array.
If you want to do so, please use a dynamically allocated 1-dim array as the pData,
and still pass the Dim1DataLength and Dim2DataLength arguments (size of array
equals to Dim1DataLength* Dim2DataLength). You can view the IntenGraph
sample program for detail.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than

16
VARAINT var=_2DimArrayToVar(zData, 100, 100);
Please do not use ArrayToVar in this way to avoid error.

_2DimArrayToVar(float* pData, int Dim1DataLength, int Dim2DataLength);


Syntax
There are two ways to use the _2DimArrayToVar class. You can:
float zData[100][100];
// fill the value of elements in zData
DIntenChart.AddPlane(_2DimArrayToVar(zData, 100, 100));
Or
float zData[100][100];
// fill the value of elements in zData
_2DimArrayToVar var(zData, 100, 100);
DIntenChart.AddPlane(var);
Argument
pData : the pointer of the 2-dimension array to be wrapped in a VARIANT
structure
Dim1DataLength: number of elements of 1st dimension of the array
Dim2DataLength: number of elements of 2nd dimension of the array
Remark
Call this function to wrap the 2-dimension float array in a VARIANT structure.
The Dim1DataLength and Dim2DataLength argument can be equal to or smaller
than the actual size you declare in the array. Dim1DataLength and
Dim2DataLength greater than the actual size of array may cause memory access
violation.Remember that in VC++, you can not dynamically declare a 2-dim array.
If you want to do so, please use a dynamically allocated 1-dim array as the pData,
and still pass the Dim1DataLength and Dim2DataLength arguments (size of array
equals to Dim1DataLength* Dim2DataLength). You can view the IntenGraph
sample program for detail.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=_2DimArrayToVar(zData, 100, 100);
Please do not use ArrayToVar in this way to avoid error.

_2DimArrayToVar(double* pData, int Dim1DataLength, int

17
Dim2DataLength)
Syntax
There are two ways to use the _2DimArrayToVar class. You can:
double zData[100][100];
// fill the value of elements in zData
DIntenChart.AddPlane(_2DimArrayToVar(zData, 100, 100));
Or
double zData[100][100];
// fill the value of elements in zData
_2DimArrayToVar var(zData, 100, 100);
DIntenChart.AddPlane(var);
Argument
pData : the pointer of the 2-dimension array to be wrapped in a VARIANT
structure
Dim1DataLength: number of elements of 1st dimension of the array
Dim2DataLength: number of elements of 2nd dimension of the array
Remark
Call this function to wrap the 2-dimension double array in a VARIANT structure.
The Dim1DataLength and Dim2DataLength argument can be equal to or smaller
than the actual size you declare in the array. Dim1DataLength and
Dim2DataLength greater than the actual size of array may cause memory access
violation.
Remember that in VC++, you can not dynamically declare a 2-dim array. If you
want to do so, please use a dynamically allocated 1-dim array as the pData, and
still pass the Dim1DataLength and Dim2DataLength arguments (size of array
equals to Dim1DataLength* Dim2DataLength). You can view the IntenGraph
sample program for detail.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var=_2DimArrayToVar(zData, 100, 100);
Please do not use ArrayToVar in this way to avoid error.

MultiArrayToVar Class
The MultiArrayToVar class helps you to combine two or more 1-Dimension arrays into
one and wrapp it in the VARIANT structure. This could be useful for DChart, DGraph,

18
and DXYGraph. For example, if you get three individual arrays and want to plot these
arrays, you can use MultiArrayToVar class to combine them into one and pass to
DChart.Plot(). Notice that we only provide double type array as argument, this is
because double type array is most common data type and acceptable for DChart,
DGraph, and DXYGraph. We also take the advantage of polymorphism in C++ to
provide overloading constructors.

class MultiArrayToVar : public tagVARIANT


{
public:
MultiArrayToVar(double* pData1, double* pData2, int DataLength);
MultiArrayToVar(double* pData1, double* pData2, double* pData3,
int DataLength);
MultiArrayToVar(double* pData1, double* pData2, double* pData3,
double* pData4, int DataLength);
MultiArrayToVar(double* pData1, double* pData2, double* pData3,
double* pData4, double* pData5, int DataLength);
MultiArrayToVar(double* pData1, double* pData2, double* pData3,
double* pData4, double* pData5, double* pData6,
int DataLength);
MultiArrayToVar(double* pData1, double* pData2, double* pData3,
double* pData4, double* pData5, double* pData6,
double* pData7, int DataLength);
MultiArrayToVar(double* pData1, double* pData2, double* pData3,
double* pData4, double* pData5, double* pData6,
double* pData7, double* pData8, int DataLength);
~MultiArrayToVar();
}

The member functions of MultiArrayToVar Class :


MultiArrayToVar(double* pData1, double* pData2, int DataLength);
Syntax
There are two ways to use the ArrayToVar class. You can:
double dataArray1[100];
double dataArray2[100];
// fill the value of elements in these arrays
DChart.PlotChart(MultiArrayToVar (dataArray1, dataArray2, 100));
Or

19
double dataArray1[100];
double dataArray2[100];
// fill the value of elements in these arrays
ArrayToVar var(dataArray1, dataArray2, 100);
DChart.PlotChart(var);
Argument
pData1: the pointer of the 1st array to be wrapped in a VARIANT structure
pData2: the pointer of the 2nd array to be wrapped in a VARIANT structure
DataLength: number of elements of the array
Remark
Call this function to combine two arrays into one and wrap the combined array in a
VARIANT structure. While 1st and 2nd arrays are in the format : {P1-1, P1-2,
P1-3, … , P1-n}, {P2-1, P2-2, P2-3, … , P2-n}, the combined array is in the
following format : {P1-1, P2-1, P1-2, P2-2, P1-3, P2-3, … , P1-n, P2-n}.
The DataLength argument should be equal to or smaller than the minimal value of
(data number of pData1, data number of pData2). DataLength greater than the
expected size may cause memory access violation.
Caution
The array data wrapped in a VARIANT is only accessible during the lifetime of the
class object. That means, after the object destroyed, accessing the array data it
contains will cause access violation. That’s why we suggested you to use this class
in above two ways, rather than
VARAINT var= MultiArrayToVar(dataArray1, dataArray2, 100);
Please do not use ArrayToVar in this way to avoid error.

The manipulation of the rest overloading constructors of MultiArrayToVar are the


same as MultiArrayToVar(double* pData1, double* pData2, int DataLength).

20

You might also like