Professional Documents
Culture Documents
VarPacker Ref
VarPacker Ref
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.
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
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.
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.
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.
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.
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.
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.
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.
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();
};
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.
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.
12
VARAINT var=ArrayToVar(floatArray, 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.
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();
};
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.
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.
16
VARAINT var=_2DimArrayToVar(zData, 100, 100);
Please do not use ArrayToVar in this way to avoid error.
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.
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.
20