# ctaQueryServices

Obtains a list of available services.

#### Prototype

DWORD ctaQueryService ( CTAHD ctahd, CTA_SERVICE_NAME *svclist[], unsigned size, unsigned *count)

Argument | Description
ctahd | Context handle that specifies the server on which commands are executed. ctahd can be a void context handle.
svclist | Pointer to a list of Natural Access service names. The CTA_SERVICE_NAME_BUF structure is: typedef struct { char svcname[CTA_MAXSVCNAME_LEN + 1]; char svcmgrname[CTA_MAXSVCNAME_LEN + 4]; } CTA_SERVICE_NAME_BUF;
size | The size of the CTA_SERVICE_NAME_BUF array passed. Set to 0 (zero) to determine the number of services available on a Natural Access Server (ctdaemon).
count | Pointer to the returned number of service names.

#### Return values

Return value | Description
SUCCESS |
CTA_BAD_ARGUMENT | Invalid server address.
CTAERR_NOT_IMPLEMENTED | Function is not available in the execution mode associated with the specified context.
CTAERR_NOT_INITIALIZED | Natural Access is not initialized. Call ctaInitialize first.
CTAERR_SVR_COMM | Server communication error.

#### Details

ctaQueryServices obtains a list of services available on the Natural Access Server (ctdaemon) specified by ctahd. If the size of svclist is less than the current number of services on a server (but not zero), the maximum possible number of services are returned.

#### See also

ctaOpenServices

#### Example

int DemoQueryServices(CTAHD ctahd)
{
unsigned size, count;
DWORD ret;
ret = ctaQueryServices(ctahd,NULL,0,&size);
if ( ret != SUCCESS )
return ret;
CTA_SERVICE_NAME_BUF* svclist = (CTA_SERVICE_NAME_BUF*)
malloc(size * sizeof(CTA_SERVICE_NAME_BUF));
ret = ctaQueryServices(ctahd,svclist,size,&count);
if ( ret != SUCCESS )
return ret;
for (unsigned i = 0;i< count; i++)
printf("Service: %s, Service manager: %s\n",
svclist[i].svcname,svclist[i].svcmgrname);
free(svclist);
return SUCCESS;
}