# ctaAttachObject

Attaches to an existing service object.

#### Prototype

DWORD ctaAttachObject ( CTAHD *ctahd, char *descriptor, unsigned *objhd)

Argument | Description
ctahd | Pointer to a context handle.
descriptor | Pointer to a service object descriptor created by or obtained from another application.
objhd | Pointer to a returned object handle.

#### Return values

Return value | Description
SUCCESS |
CTAERR_BAD_ARGUMENT | Invalid object descriptor.
CTAERR_NOT_FOUND | Invalid context.
CTAERR_NOT_IMPLEMENTED | This function is not available in the execution mode associated with the specified context.
CTAERR_NOT_INITIALIZED | Natural Access is not initialized. Call ctaInitialize first.

#### Details

ctaAttachObject enables applications using local or remote instances of Natural Access Server (ctdaemon) to share service objects. To use this function, the applications must share the context that is associated with the service object.

The application creating the service object must either specify the descriptor or obtain the descriptor with ctaGetObjDescriptor. The application passes the descriptor to another application. The second application can then use ctaAttachObject and the descriptor to attach to the service object. When ctaAttachObject returns, objhd contains an object handle and ctahd contains the context handle of the context that is associated with the attached service object. Subsequently, the application can use the objhd to access the service object.

For more information, see Sharing contexts.

#### See also

ctaDetachObject

#### Example

int DemoAttachDetach(char* contextname, char* objname)
{
DWORD ret;
CTAQUEUEHD ctaqueuehd;
char *mgrlist[] = { "ADIMGR", "ADIMGR", "VCEMGR", "SWIMGR"};
ret = ctaCreateQueue( mgrlist,
sizeof(mgrlist)/sizeof(mgrlist[0]),
&ctaqueuehd);
if ( ret != SUCCESS )
return ret;
// Attach to existing server context
CTAHD ctahd;
ret = ctaAttachContext(ctaqueuehd,0,contextname,&ctahd);
if ( ret != SUCCESS )
return ret;
// Attach to existing call
unsigned callhd;
ret = ctaAttachObject(&ctahd,objname,&callhd);
if ( ret != SUCCESS )
return ret;
printf("Attached to call 0x%08X\n",callhd);
// Get call status
NCC_CALL_STATUS info;
ret = nccGetCallStatus( callhd, &info, sizeof( NCC_CALL_STATUS ) );
if ( ret != SUCCESS )
return ret;
printf("Called number: %s\n",info.calledaddr );
// Detach from the call
ret = ctaDetachObject(callhd);
if ( ret != SUCCESS )
return ret;
printf("Detached\n");
return SUCCESS;
}