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

# XInputSetStateEx

> XInputSetStateEx

# XInputSetStateEx

将振动数据发送到指定的控制器。支持较新控制器的四电机振动功能。

<a id="syntaxSection" />

## 语法

```cpp theme={null}
DWORD XInputSetStateEx(  
         DWORD dwUserIndex,  
         const XINPUT_VIBRATION_EX * pVibration  
)  
```

<a id="parametersSection" />

### 参数

*dwUserIndex*   \_In\_\
类型：DWORD

与设备关联的玩家索引；取值范围为 0 到 `XUSER_MAX_COUNT - 1`。

*pVibration*   \_In\_\
类型：[XINPUT\_VIBRATION\_EX](/reference/input/xinputongameinput/structs/xinput_vibration_ex)\*

指向 [XINPUT\_VIBRATION\_EX](/reference/input/xinputongameinput/structs/xinput_vibration_ex) 对象的指针，其中包含要发送到控制器的振动信息。

<a id="retvalSection" />

### 返回值

类型：DWORD

如果函数成功，则返回 `ERROR_SUCCESS`。

如果未连接控制器，函数将返回 `ERROR_DEVICE_NOT_CONNECTED`。

如果函数失败，将返回 WinError.h 中定义的错误代码。

<a id="remarksSection" />

## 备注

即使在与双电机控制器交互期间，调用此函数也是安全的。任何发送到 `XInputSetStateEx` 用于双电机控制器的振动设置都将被调整，以确保控制器仍能以最接近输入的方式进行振动。因此，我们建议你在原本会调用 [XInputSetState](/reference/input/xinputongameinput/functions/xinputsetstate) 的场景中调用 `XInputSetStateEx`。

有关详细信息，请参阅 [XInputOnGameInput 包装器](/build/core-features/common/input/porting/input-porting-xinput#xinputWrapperSection)。

<a id="requirementsSection" />

## 要求

**头文件：** XInputOnGameInput.h

**库：** xgameruntime.lib

**支持的平台：** XBOX One 系列主机和 XBOX Series 主机

<a id="seealsoSection" />

## 另请参阅

[从 XInput 移植到 GameInput](/build/core-features/common/input/porting/input-porting-xinput)\
[XInputOnGameInput](/reference/input/xinputongameinput/xinputongameinput_members)


## Related topics

- [XInputSetState](/zh-CN/reference/input/xinputongameinput/functions/xinputsetstate.md)
- [XINPUT_VIBRATION_EX](/zh-CN/reference/input/xinputongameinput/structs/xinput_vibration_ex.md)
- [XINPUT_VIBRATION](/zh-CN/reference/input/xinputongameinput/structs/xinput_vibration.md)
- [XInputOnGameInput](/zh-CN/reference/input/xinputongameinput/xinputongameinput_members.md)
- [从 XInput 移植到 GameInput](/zh-CN/build/core-features/common/input/porting/input-porting-xinput.md)
