# cbWinArrayToBuf()

Copies data from an array into a Windows memory buffer.

## Function Prototype

C/C++

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

Visual Basic

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

## Arguments

DataArray

The array containing the data to be copied.

MemHandle

This must be a memory handle that was returned by cbWinBufAlloc() when the buffer was allocated. The data will be copied into this buffer.

FirstPoint

Index of first point in memory buffer where data will be copied to.

Count

Number of data points to copy.

## Returns

- Error code or zero if no errors.

## Notes

- This function copies data from an array to a Windows global memory buffer. This would typically be used to initialize the buffer with data before doing an output scan. Using the FirstPoint and Count arguments it is possible to fill a portion of the buffer. This can be useful if you want to send new data to the buffer after a BACKGROUND+CONTINUOUS output scan has been started – for example, during circular buffering.
- Although this function is available to Windows C, 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 an array to a memory buffer.
- Refer to the following example:

long Count= 1000;
unsigned short *DataArray=NULL;
int MemHandle = 0;
/*allocate the buffer and cast it to an unsigned short*/
MemHandle = cbWinBufAlloc(Count);
DataArray = (unsigned short*)MemHandle;
/*calculate and store the waveform*/
for(int i=0; i<Count; ++i)

DataArray[i] = 2047*(1.0 + sin(6.2832*i/Count));

/*output the waveform*/
cbAOutScan(......,MemHandle,...);
/*free the buffer and NULL the pointer*/
cbWinBufFree(MemHandle);
DataArray = NULL;