删除某一回调方法。 将不再调用该方法,并且您可以在 UnregisterCallback 完成后从回调函数删除资源。
语法
bool UnregisterCallback(
GameInputCallbackToken callbackToken,
uint64_t timeoutInMicroseconds
)
参数
callbackToken _In_
类型:GameInputCallbackToken
要注销的回调函数的标记。 在使用 IGameInput::RegisterDeviceCallback 最初注册函数时生成。
timeoutInMicroseconds _In_
类型:uint64_t
等待某一回调完成以便可将其注销的时间量。
返回值
类型:bool
如果已成功注销回调则返回 True。 False 指示在等待某一进行中的回调返回时超时。 返回 false 将仍确保不会调度任何新回调,已在进行中的回调仍将执行。
备注
IGameInput::StopCallback 方法和 IGameInput::UnregisterCallback 方法稍有不同。 调用这两种方法中的任何一种都确保不会重新调度关联的回调。 但是,在 UnregisterCallback 函数成功返回前,释放与该回调相关的任何资源都是不安全的(例如,上传托管回调函数的 DLL)。 因此,无法从其已注册的回调函数内注销某一回调,并且尝试这样做会导致返回错误。 但是,从回调函数内取消某一回调是安全的。
以下 C++ 示例演示了如何在断开游戏板或键盘时收到通知。
Microsoft::WRL::ComPtr<IGameInput> gameInput;
void CALLBACK OnDeviceDisconnected(
_In_ GameInputCallbackToken callbackToken,
_In_ void * context,
_In_ IGameInputDevice * device,
_In_ uint64_t timestamp,
_In_ GameInputDeviceStatus currentStatus,
_In_ GameInputDeviceStatus previousStatus,
)
{
if (!(currentStatus & GameInputDeviceConnected))
{
// Application-specific code to handle the device disconnection
}
}
void WaitForDisconnectWorker(
_In_ IGameInputDevice * device,
_In_ volatile bool & cancelWait) noexcept
{
GameInputCallbackToken token;
if (SUCCEEDED(gameInput->RegisterDeviceCallback(
device, // Watch for the specific input device
GameInputKindGamepad | GameInputKindKeyboard, // Listen for changes with gamepads and keyboards
GameInputDeviceConnected, // Notify on changes to GameInputDeviceConnected status
GameInputNoEnumeration, // No initial enumeration needed
nullptr, // No callback context parameter
OnDeviceDisconnected, // Callback function
&token))) // Generated token
{
while (!cancelWait)
{
Sleep(100);
}
gameInput->UnregisterCallback(token, 5000);
}
}
要求
头文件:GameInput.h
库:xgameruntime.lib
支持平台:Windows、Xbox One 系列主机和 Xbox Series 主机
另请参阅
输入 API 概述
IGameInput
IGameInput::RegisterDeviceCallback
IGameInput::RegisterReadingCallback
IGameInput::RegistersystemButtonCallback