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

# Updating a user's Presence via XSAPI C

> Flat C sample using XblPresenceSetPresenceAsync to update an XBOX Live user's online Presence status and advertise current in-game activity.

This topic provides example code for setting a user's online Presence status. XBOX services Rich Presence provides features for advertising a player's current activity to other players.

For more information, see [Rich Presence overview](/services/xbox-services/community/presence/live-presence-overview).

## Updating a user's online Presence status

This example code sets a user's online Presence status.

#### Flat C API

```cpp theme={null}
auto asyncBlock = std::make_unique<XAsyncBlock>();
asyncBlock->queue = queue;
asyncBlock->context = nullptr;
asyncBlock->callback = [](XAsyncBlock* asyncBlock)
{
    std::unique_ptr<XAsyncBlock> asyncBlockPtr{ asyncBlock }; // Take over ownership of XAsyncBlock*.
    HRESULT hr = XAsyncGetStatus(asyncBlock, false);
};

HRESULT hr = XblPresenceSetPresenceAsync(xboxLiveContext, true, nullptr, asyncBlock.get());
if (SUCCEEDED(hr))
{
    // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* because the callback will take over ownership.
    // If the call fails, std::unique_ptr will keep ownership and delete XAsyncBlock*.
    asyncBlock.release();
}
```

For more information, see the following:

* [XAsyncBlock](/reference/system/xasync/structs/xasyncblock)
* [XAsyncGetStatus](/reference/system/xasync/functions/xasyncgetstatus)
* [XblPresenceSetPresenceAsync](/reference/live/xsapi-c/presence_c/functions/xblpresencesetpresenceasync)

## Updating Rich Presence status

#### Flat C API

```cpp theme={null}
XblPresenceRichPresenceIds ids{};
pal::strcpy(ids.scid, sizeof(ids.scid), scid);
ids.presenceId = "playingMap";
std::vector<const char*> tokenIds{ "CurrentMap" };
ids.presenceTokenIds = tokenIds.data();
ids.presenceTokenIdsCount = tokenIds.size();

HRESULT hr = XblPresenceSetPresenceAsync(xboxLiveContext, true, &ids, asyncBlock.get());
```

For more information, see the following:

* [XblPresenceRichPresenceIds](/reference/live/xsapi-c/presence_c/structs/xblpresencerichpresenceids)
* [XblPresenceSetPresenceAsync](/reference/live/xsapi-c/presence_c/functions/xblpresencesetpresenceasync)


## Related topics

- [Rich Presence example code](/services/xbox-services/community/presence/how-to/live-presence-howto-nav.md)
- [How to](/services/xbox-services/community/presence/how-to/index.md)
- [Updating a user's Presence via REST](/services/xbox-services/community/presence/how-to/live-updating-presence-rest.md)
- [XblPresenceTrackUsers](/reference/live/xsapi-c/presence_c/functions/xblpresencetrackusers.md)
- [Updating title-managed Achievements](/services/xbox-services/player-data/achievements/title-managed/how-to/live-how-to-update-achievements.md)
