cbWinBufToArray()

Copies data from a Windows memory buffer into an array.

Function Prototype

C/C++

int cbWinBufToArray(int MemHandle, unsigned short* DataArray, long FirstPoint, long Count)

Visual Basic

Function cbWinBufToArray(ByVal MemHandle&, DataArray%, ByVal FirstPoint&, ByVal Count&) As Long

Arguments

MemHandle

This must be a memory handle that was returned by cbWinBufAlloc() when the buffer was allocated. The buffer should contain the data that you want to copy.

DataArray

The array that the data is copied to.

FirstPoint

Index of the first point in the memory buffer that data is copied from.

Count

Number of data points to copy.

Returns

Notes

Using the FirstPoint and Count argument it is possible to copy only a portion of the buffer to the array. This can be useful if you want foreground code to manipulate previously collected data while a BACKGROUND scan continues to collect new data.

Although this function is available to Windows C programs, it is not necessary, since it is possible to manipulate the memory buffer directly by casting the MemHandle returned from cbWinBufAlloc() to the appropriate type. This method avoids having to copy the data from the memory buffer to an array.

Refer to the following example:

/*declare and initialize the variables*/
long Count=1000;
unsigned short *DataArray=NULL;
int MemHandle=0;




/*allocate the buffer and cast it to a pointer to an unsigned short*/
MemHandle = cbWinBufAlloc(Count);
DataArray = (unsigned short*)MemHandle;




/*Scan the waveform data*/
cbAInScan(......,MemHandle,...);




/*print the results*/
for(int i=0; i<Count; ++i)

printf("Data[%d]=%d\n", i, DataArray[i])




/*free the buffer and NULL the pointer*/
cbWinBufFree(MemHandle);
DataArray = NULL;