> ## 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.

# IXtfInputClient::ConnectGamepad Method

> IXtfInputClient::ConnectGamepad Method

# IXtfInputClient::ConnectGamepad Method

创建虚拟控制器，并获取其设备标识符。

<a id="syntaxSection" />

## 语法

```cpp theme={null}
public:
HRESULT ConnectGamepad(
         UINT64 *pControllerId
)  
```

<a id="ID4EG" />

### 参数

*pControllerId*\
类型：UINT64 \*

指向 UINT64 的指针，用于接收此 [IXtfInputClient](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/ixtfinputclient-xtfinput-xbox-windows-t) 的设备标识符。

<a id="ID4EP" />

### 返回值

类型：HRESULT

HRESULT 成功或错误代码。

<a id="remarks" />

## 备注

**ConnectGamepad** 为创建的每个虚拟控制器分配系统资源，并返回将用于通过 [IXtfInputClient::SendGamepadReport](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/methods/sendgamepadreport-ixtfinputclient-xtfinput-xbox-windows-m) 向开发主机发送输入的虚拟控制器的标识符。你的代码在调用 **ConnectGamepad** 后应等待 2 秒再调用 [SendGamepadReport](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/methods/sendgamepadreport-ixtfinputclient-xtfinput-xbox-windows-m)，以确保主机已完成新控制器的注册并准备好接受输入。你的代码应始终将对 **ConnectGamepad** 的调用与对 [DisconnectGamepad](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/methods/disconnectgamepad-ixtfinputclient-xtfinput-xbox-windows-m) 的调用配对，以确保这些系统资源被释放以供重用。你也可以调用 [IXtfInputClient::DisconnectAllGamepads](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/methods/disconnectgamepad-ixtfinputclient-xtfinput-xbox-windows-m) 一次性释放所有虚拟控制器资源。

<a id="requirements" />

## 要求

**头文件：** xtfinput.h

**库：** xtfinput.lib

**支持的平台：** Windows（用于 XBOX 主机工具）

## 另请参阅

[XtfInput](/reference/tools/xtf/xtfinput/xtfinput-xbox-microsoft-n)\
[IXtfInputClient](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/ixtfinputclient-xtfinput-xbox-windows-t)\
[IXtfInputClient::ConnectGamepad](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/methods/connectgamepad-ixtfinputclient-xtfinput-xbox-windows-m)\
[IXtfInputClient::DisconnectGamepad](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/methods/disconnectgamepad-ixtfinputclient-xtfinput-xbox-windows-m)\
[IXtfInputClient::DisconnectAllGamepads](/reference/tools/xtf/xtfinput/classes/IXtfInputClient/methods/disconnectgamepad-ixtfinputclient-xtfinput-xbox-windows-m)
