# vceRead

Reads data at the current position in the current message.

#### Prototype

DWORD vceRead ( CTAHD ctahd, BYTE *buffer, unsigned bytes, unsigned *bytesread)

Argument | Description
ctahd | Handle returned by ctaCreateContext or ctaAttachContext.
buffer | Pointer to a buffer to receive data.
bytes | Amount of data to read.
bytesread | Pointer to the returned number of bytes read.

#### Return values

Return value | Description
SUCCESS |
CTAERR_FUNCTION_ACTIVE | Playing or recording is active on the context.
CTAERR_INVALID_CTAHD | Context handle is invalid.
CTAERR_SVR_COMM | Server communication error.
VCEERR_NO_MESSAGE | There is no current message in the context.

#### Details

vceRead copies the specified number of bytes of data at the current location in the current message in the context specified by ctahd to a specified buffer. It returns the number of bytes read in bytesread, unless bytesread is NULL.

The number of bytes read is always an integral multiple of the framesize of the current message. If you specify a buffer size that is not a multiple of the framesize, the number of bytes read is smaller than the requested size.

The following restrictions apply to using vceRead:

- EDTX encoding types are not supported.

- You cannot read while play or record is active.

- If you attempt to read beyond the end of the current message, SUCCESS is returned and the current position is set to the end of the current message.

- The current position is advanced by the amount read in millisecond units.

To convert between bytes and milliseconds, use vceGetContextInfo to get the frame size and frame time, then use the following formulas:

milliseconds = (bytes / framesize) * frametime

bytes = (milliseconds / frametime) * framesize

#### See also

vceWrite

#### Example

/* Read a message into memory */
void myLoadMessage (CTAHD ctahd, VCEHD vh, unsigned message,
BYTE **returned_address, unsigned *returned_msec,
unsigned *returned_bytes)
{
VCE_CONTEXT_INFO contextinfo;
unsigned msec;
unsigned bytes;
unsigned bytesread;
BYTE *buffer;
*returned_address = NULL;
*returned_msec = 0;
vceSetCurrentMessage (vh, message) ;
vceGetCurrentSize (ctahd, &msec) ;
if (msec == 0)
return ;
/* Convert the size from milliseconds to bytes */
vceGetContextInfo (ctahd, &contextinfo, sizeof contextinfo);
bytes = msec / contextinfo.frametime * contextinfo.framesize;
buffer = malloc(bytes) ;
vceRead (ctahd, buffer, bytes, &bytesread);
*returned_address = buffer;
*returned_msec = msec;
*returned_bytes = bytes;
return;
}