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

# XGameInviteEventCallback (deprecated)

> XGameInviteEventCallback (deprecated)

# XGameInviteEventCallback (deprecated)

<Info>此 API 现已弃用。请改用 [XGameActivationCallback](/reference/system/xgameactivation/functions/xgameactivationcallback)。</Info>

应用程序为游戏邀请事件定义的回调。

## Syntax

```cpp theme={null}
void XGameInviteEventCallback(  
         void* context,  
         const char* inviteUri  
)  
```

### Parameters

*context*   \_In\_opt\_\
类型：void\*

传递给 [XGameInviteRegisterForEvent](/reference/system/xgameinvite/functions/xgameinviteregisterforevent) 的上下文。

*inviteUri*   \_In\_\
类型：char\*

用于加入游戏会话的 URI。
<Note>XSAPI 知道如何使用该 URI。</Note>

### Return value

类型：void

<a id="ID_XGameInviteEventCallback_Remarks" />

## Remarks

若要为游戏邀请事件注册回调，请调用 [XGameInviteRegisterForEvent](/reference/system/xgameinvite/functions/xgameinviteregisterforevent)。该函数使用指向 **XGameInviteEventCallback** 的指针作为参数。

若要取消注册游戏邀请事件的回调，请调用 [XGameInviteUnregisterForEvent](/reference/system/xgameinvite/functions/xgameinviteunregisterforevent)。

以下代码示例注册游戏邀请回调。

```cpp theme={null}
#include <XTaskQueue.h>
#include <XGameInvite.h>  
  
XTaskQueueHandle g_taskQueue;  
XTaskQueueRegistrationToken g_gameInviteEventToken;  
  
void OnGameInvite(void* context, const char* inviteUri)  
{  
    if (inviteUri != nullptr)
    {
        std::string inviteString(inviteUri);
        auto pos = inviteString.find("handle=");
        auto inviteHandeId = inviteString.substr(pos + 7, 36);
        // Now call XblMultiplayerManagerJoinLobby if using MPM
        // or call XblMultiplayerWriteSessionByHandleAsync if using MPSD APIs
    }
}  
  
void InitializeGame()  
{  
    XGameInviteRegisterForEvent(g_taskQueue, nullptr, OnGameInvite, &g_gameInviteEventToken);  
}  
  
void ShutdownGame()  
{  
    XGameInviteUnregisterForEvent(g_gameInviteEventToken);  
}  
```

## Requirements

**头文件：** XGameInvite.h

**库：** xgameruntime.lib

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

## See also

[XGameInvite](/reference/system/xgameinvite/xgameinvite_members)

[XGameInviteRegisterForEvent](/reference/system/xgameinvite/functions/xgameinviteregisterforevent)

[XGameInviteUnregisterForEvent](/reference/system/xgameinvite/functions/xgameinviteunregisterforevent)


## Related topics

- [XGameInviteUnregisterForEvent (deprecated)](/zh-CN/reference/system/xgameinvite/functions/xgameinviteunregisterforevent.md)
- [XGameInviteRegisterForEvent (deprecated)](/zh-CN/reference/system/xgameinvite/functions/xgameinviteregisterforevent.md)
- [XGameInvite (deprecated)](/zh-CN/reference/system/xgameinvite/xgameinvite_members.md)
- [XGameActivationCallback](/zh-CN/reference/system/xgameactivation/functions/xgameactivationcallback.md)
- [XGameProtocolActivationCallbackXGameProtocol (deprecated)](/zh-CN/reference/system/xgameprotocol/functions/xgameprotocolactivationcallback.md)
