# vceOpenMemory

Assigns a voice handle to a memory block.

#### Prototype

DWORD vceOpenMemory ( CTAHD ctahd, BYTE *address, unsigned bytes, unsigned encoding, VCEHD *vh)

Argument | Description
ctahd | Handle returned by ctaCreateContext.
address | Base address of the memory block in process space or shared memory.
bytes | Size of the memory block, in bytes.
encoding | Type of voice encoding of all data in the memory block.
vh | Pointer to a returned voice handle.

#### Return values

Return value | Description
SUCCESS |
CTAERR_INVALID_CTAHD | Context handle is invalid.
CTAERR_NOT_IMPLEMENTED | This error is returned when an application that is not using the inproc default server launches vceOpenMemory.
VCEERR_UNSUPPORTED_ENCODING | Neither the Voice Message service nor the associated play or record service, if any, supports the specified encoding.

#### Details

vceOpenMemory assigns a voice handle to a range of the application memory. The size is specified in bytes.

vceOpenMemory is not supported when using the localhost default server. Use vceCreateMemory to allocate a memory block and assign a voice handle to it. vceCreateMemory can be launched when using either the inproc default server or the localhost default server.

An open memory object has initially only one non-empty message that is assigned message zero (0). The size of this message is equal to the size of the memory block. To record other than to message zero (0), either erase message zero (0), or resize it by recording or writing a message that is smaller than the entire memory block.

If your memory block contains multiple messages, use vceDefineMessages to tell the Voice Message service how the memory is partitioned.

Memory is always opened in PLAY_RECORD mode. There is no protection against opening overlapping memory regions. There is no interlock to prevent multiple threads recording to the same area from different contexts.

Unlike voice files, memory objects cannot grow.

Note: Recording to a memory object ends with CTA_REASON_FINISHED if the message is bounded by the next message or if the end of the memory block is reached.

vceClose releases the handle and internal resources.

Natural Access does not allocate the memory block in vceOpenMemory or free it in vceClose.

#### See also

vceAssignHandle, vceCreateFile, vceErase, vceEraseMessage, vceOpenFile

#### Example

/* myCreateMemory - Allocate a block of memory and get a voice handle to it. */
void myCreateMemory (CTAHD ctahd, unsigned maxtime, unsigned encoding, VCEHD *vh)
{
unsigned framesize;
unsigned frametime;
unsigned bytes;
void *address;
vceGetEncodingInfo (ctahd, encoding, &framesize, &frametime);
bytes = maxtime/frametime * framesize;
address = malloc (bytes);
vceOpenMemory (ctahd, address, bytes, encoding, vh);
}