# vceAssignHandle

Assigns a voice handle to an open file.

#### Prototype

DWORD vceAssignHandle ( CTAHD ctahd, int filedes, unsigned encoding, VCEHD *vh)

Argument | Description
ctahd | Handle returned by ctaCreateContext.
filedes | File descriptor returned by an operating system open function.
encoding | Encoding of all messages in the file.
vh | Pointer to a returned voice handle.

#### Return values

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

#### Details

vceAssignHandle assigns a voice handle to an open file or to some other data stream such as stdin.

When vceClose closes the voice handle, filedes is not automatically closed.

The Voice Message service marks the voice handle that vceAssignHandle returns as thread-safe so that multiple voice handles can be assigned to the same open file. For example, multiple contexts running in separate threads can safely access a common prompt file without incurring the overhead of multiple file opens.

The record or edit function returns a write failed error code if the file has not been opened for writing.

Note: In UNIX, you can use the file descriptor that the C open function or the C fileno function returns. In Windows, because some compilers do not return the operating system file descriptor, you can use file descriptors returned only by system calls (for example, CreateFile).

Use vceAssignHandle only if the application is using the inproc default server.

#### See also

vceCreateFile, vceOpenFile, vceOpenMemory

#### Example

/* Play from standard input */
#if defined _WIN32 && defined _MSC_VER
#include <io.h>
#define STDIN_FILENO _get_osfhandle (0)
#endif
extern CTAHD Ctahd;
extern CTAQUEUEHD CtaQueueHd;
void myplaystdin( unsigned encoding )
{
VCEHD vh;
CTA_EVENT event;
vceAssignHandle (Ctahd, STDIN_FILENO, encoding, &vh );
vcePlayMessage (vh, 0, NULL);
do
{
ctaWaitEvent( CtaQueueHd, &event, CTA_WAIT_FOREVER);
} while (event.id != VCEEVN_PLAY_DONE); /* Ignore other events */
}