> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# IAcpHal::Connect

> IAcpHal::Connect

# IAcpHal::Connect

Connects to the ACP.

## Syntax

```cpp theme={null}
HRESULT Connect(  
         UINT32 numCommands,  
         UINT32 numMessages  
)  
```

### Parameters

*numCommands*   \
Type: UINT32

Specifies the number of commands to be allocated in the ACP command queue. This value must be greater than zero and large enough to handle as many commands as were issued for each 2.67-ms audio frame.

*numMessages*   \
Type: UINT32

Specifies the number of messages to be allocated in the ACP message queue. This value can be zero if the title does not process received messages. If *command completed* messages (see [ACP\_MESSAGE\_TYPE](/reference/audio/acphal/enums/acp_message_type)) have been registered for, there will be at least as many messages as there are commands. Typically, this message queue is processed less frequently than once per audio frame, so plan for several frame's worth of messages.

### Return value

Type: HRESULT

If the method succeeds, it returns `S_OK`. If the method fails, it returns one of the following codes (partial list):

| Return code                | Description                                                                              |
| -------------------------- | ---------------------------------------------------------------------------------------- |
| E\_INVALIDARG              | One or more of the arguments are invalid, or the parameter *numCommands* is set to zero. |
| E\_OUTOFMEMORY             | Memory allocation has failed.                                                            |
| ACP\_E\_ALREADY\_CONNECTED | Already connected to the ACP.                                                            |
| E\_UNEXPECTED              | An unexpected error occurred.                                                            |
| ACP\_E\_QUEUE\_FULL        | The ACP queue is full.                                                                   |
| E\_TIMEOUT                 | A timeout error has occurred.                                                            |

## Remarks

Call this method before you call any other method in this interface. However, after calling [Disconnect](/reference/audio/acphal/interfaces/IAcpHal/methods/iacphal_disconnect), you may call this method again. See also [SubmitCommand](/reference/audio/acphal/interfaces/IAcpHal/methods/iacphal_submitcommand).

If the method fails from an error other than `E_INVALIDARG` or `ACP_E_ALREADY_CONNECTED`, it is advised for **all** existing ACP client objects to be destroyed and for allocated SHAPE contexts to be freed using [AcpHalReleaseShapeContexts](/reference/audio/acphal/functions/acphalreleaseshapecontexts). New SHAPE contexts and ACP client objects should be allocated/created again as needed using [AcpHalAllocateShapeContexts](/reference/audio/acphal/functions/acphalallocateshapecontexts) and [AcpHalCreate](/reference/audio/acphal/functions/acphalcreate) respectively.

## Requirements

**Header:** acphal.h

**Supported platforms:** XBOX One family consoles and XBOX Series consoles

## See also

[Disconnect](/reference/audio/acphal/interfaces/IAcpHal/methods/iacphal_disconnect)\
[AcpHal](/reference/audio/acphal/acphal_members)


## Related topics

- [IAcpHal](/reference/audio/acphal/interfaces/IAcpHal/iacphal.md)
- [SHAPE audio flowgraph construction best practices](/build/console-features/audio/overviews/best-practices-audio-flowgraph-construction.md)
- [IAcpHal::Disconnect](/reference/audio/acphal/interfaces/IAcpHal/methods/iacphal_disconnect.md)
- [IAcpHal::PopMessage](/reference/audio/acphal/interfaces/IAcpHal/methods/iacphal_popmessage.md)
- [IAcpHal::SubmitCommand](/reference/audio/acphal/interfaces/IAcpHal/methods/iacphal_submitcommand.md)
