Technical Reference > CtAPI Functions > Function Reference > ctClientCreate

ctClientCreate

ctClientCreate initializes the resources for a new CtAPI client instance. Once you have called ctClientCreate, you can pass the handle returned to ctOpenEx to establish communication with the CtAPI server.

Consider a situation where you try to communicate to the CtAPI server and the server takes a long time to respond (or doesn't respond at all). If you just call ctOpen, you haven't been given a handle to the CtAPI instance, so you can't cancel the ctOpen by calling ctCancelIO. But if you use ctClientCreate and then call ctOpenEx, you can use the handle returned by ctClientCreate to cancel the ctOpenEx.

Syntax

ctClientCreate()

Return Value

If the function succeeds, the return value specifies a handle. If the function does not succeed, the return value is NULL. Use GetLastError() to get extended error information.

Related Functions

ctOpen, ctOpenEx, ctClose, ctCloseEx, ctClientDestroy

Example

DWORD dwStatus = 0;
HANDLE hCtapi = ctClientCreate();
if (hCtapi == NULL) {
dwStatus = GetLastError(); // An error has occurred, trap it.
} else {
if (TRUE == ctOpenEx(NULL, NULL, NULL, 0, hCtapi)) {
ctTagWrite(hCtapi, "Fred", "1.5");
if (FALSE == ctCloseEx(hCtapi, FALSE)) {
dwStatus = GetLastError(); // An error has occurred, trap it.
}
} else {
dwStatus = GetLastError(); // An error has occurred, trap it.
}
if (FALSE == ctClientDestroy(hCtapi)) {
dwStatus = GetLastError(); // An error has occurred, trap it
}
}