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

# Lobby SDK Quickstart

> Set up the PlayFab Multiplayer C/C++ SDK and create your first PlayFab Lobby with this quickstart covering prerequisites, integration, and initial API calls.

This article describes how to set up the development environment for PlayFab Lobby and create your first lobby using the PlayFab Multiplayer C/C++ SDK.

<Note>
  The PlayFab Multiplayer SDK also provides APIs for PlayFab Matchmaking. \* For more information on C++ APIs, see the [Matchmaking SDK quickstart](/services/playfab/multiplayer/matchmaking/quickstart-client-sdk). \* For more information on Unity APIs, see the [Quickstart for Unity](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/multiplayer-unity-sdk-getting-started) \* For more information on Unreal APIs, see the [Quickstart for Unreal](/services/playfab/multiplayer/networking/party-unreal-engine-oss-quickstart)
</Note>

## Prerequisites

You need a [PlayFab account](https://developer.playfab.com) to use PlayFab Lobbies. For instructions to create an account, see [Quickstart: Game Manager](/services/playfab/live-service-management/gamemanager/quickstart).

## Download and set up the PlayFab Multiplayer SDK

Download the [C/C++ SDK](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-sdks) for your platform and integrate the provider header and library files into your build.

<Note>
  This quick start focuses on using the C/C++ SDK. For Unity and Unreal interfaces, see the following articles: \* [Quickstart for Unity](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/multiplayer-unity-sdk-getting-started) \* [Quickstart for Unreal](/services/playfab/multiplayer/networking/party-unreal-engine-oss-quickstart)
</Note>

## Log in a PlayFab entity

To use the PlayFab Lobby SDK, you need to authenticate your client using PlayFab entity keys and entity tokens. Acquire a PlayFab entity key and token pair by logging in with [LoginWithCustomId](https://learn.microsoft.com/en-us/rest/api/playfab/client/authentication/login-with-custom-id) REST API. This API is also available as a C/C++ projection via the [PlayFab Services SDK](/services/playfab/sdks/playfab-sdk-intro).

<Note>
  LoginWithCustomId is a quick way to get started with PlayFab features but is not intended to be the login mechanism you ship with. For login guidance, see [Login basics and best practices](/services/playfab/identity/player-identity/login/login-basics-best-practices).
</Note>

## Initialize the PlayFab Multiplayer SDK

Initialize the PlayFab Multiplayer SDK by following these basic steps:

1. Initialize the SDK by calling [PFMultiplayerInitialize](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayerinitialize)
2. Set the entity key and token used by the library on behalf of your players by calling [PFMultiplayerSetEntityToken](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayersetentitytoken).

```cpp theme={null}
static PFMultiplayerHandle g_pfmHandle = nullptr;
...
...
HRESULT hr = S_OK;

// Initialize the PFMultiplayer library.
hr = PFMultiplayerInitialize(titleId, &g_pfmHandle);
if (FAILED(hr))
{
    // handle initialize failure
    printf("PFMultiplayerInitialize failed! %s\n", PFMultiplayerGetErrorMessage(hr));
    return hr;
}

// Set an entity token for a local user. The token is used to authenticate PlayFab operations on behalf of this user. 
// Tokens can expire, and this API token should be called again when this token is refreshed.
hr = PFMultiplayerSetEntityToken(g_pfmHandle, localUserEntity, entityToken);
if (FAILED(hr))
{
    // handle set entity token failure
    printf("PFMultiplayerSetEntityToken failed! %s\n", PFMultiplayerGetErrorMessage(hr));
    return hr;
}
```

## Create a lobby

Finally, we'll create a lobby by following these basic steps:

1. Call [PFMultiplayerCreateAndJoinLobby](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayercreateandjoinlobby)
2. Check for asynchronous completion by periodically polling [PFMultiplayerStartProcessingLobbyStateChanges](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayerstartprocessinglobbystatechanges) for a [PFLobbyCreateAndJoinLobbyCompletedStateChange](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/functions/pfmultiplayerstartprocessinglobbystatechanges).

```cpp theme={null}
PFLobbyCreateConfiguration lobbyConfiguration{};
lobbyConfiguration.maxMemberCount = 16;
lobbyConfiguration.ownerMigrationPolicy = PFLobbyOwnerMigrationPolicy::Automatic;
lobbyConfiguration.accessPolicy = PFLobbyAccessPolicy::Public;

PFLobbyJoinConfiguration memberConfiguration{};

PFLobbyHandle lobby;
HRESULT hr = PFMultiplayerCreateAndJoinLobby(g_pfmHandle, localUserEntity, &lobbyConfiguration, &memberConfiguration, nullptr, &lobby);
if (FAILED(hr))
{
    // handle immediate create failure
    printf("PFMultiplayerCreateAndJoinLobby failed! %s\n", PFMultiplayerGetErrorMessage(hr));
    return hr;
}

// NOTE: to simplify this quickstart, we'll synchronously block waiting for the CreateAndJoinLobby operation
// to finish. In a real implementation, this polling would be done asynchronously on a background thread/worker.
bool createAndJoinLobbyFinished = false;
while (!createAndJoinLobbyFinished)
{
    uint32_t lobbyStateChangeCount;
    const PFLobbyStateChange * const * lobbyStateChanges;
    HRESULT hr = PFMultiplayerStartProcessingLobbyStateChanges(m_pfmHandle, &lobbyStateChangeCount, &lobbyStateChanges);
    if (FAILED(hr))
    {
        // handle the failure
        printf("PFMultiplayerStartProcessingLobbyStateChanges failed! %s\n", PFMultiplayerGetErrorMessage(hr));
        return hr;
    }

    for (uint32_t i = 0; i < lobbyStateChangeCount; ++i)
    {
        const PFLobbyStateChange* stateChange = lobbyStateChanges[i];
        switch (stateChange->stateChangeType)
        {
            case PFLobbyStateChangeType::CreateAndJoinLobbyCompleted:
            {
                auto createAndJoinStateChange = 
                    static_cast<const PFLobbyCreateAndJoinLobbyCompletedStateChange*>(stateChange);

                if (SUCCEEDED(createAndJoinStateChange->result))
                {
                    // lobby successfully created!
                    printf("Lobby 0x%p successfully created!\n", createAndJoinStateChange->lobby);
                }
                else
                {
                    // report asynchronous failure
                    printf("Failed to create lobby 0x%p! %s\n",
                        createAndJoinStateChange->lobby,
                        PFMultiplayerGetErrorMessage(createAndJoinStateChange->result));
                }
                createAndJoinLobbyFinished = true;
                break;
            }
        }
    }

    hr = PFMultiplayerFinishProcessingLobbyStateChanges(m_pfmHandle, lobbyStateChangeCount, lobbyStateChanges);
    if (FAILED(hr))
    {
        printf("PFMultiplayerFinishProcessingLobbyStateChanges failed! %s\n", PFMultiplayerGetErrorMessage(hr));
        return hr;
    }
}
```

For more information on creating lobbies, see [Create a Lobby](/services/playfab/multiplayer/lobby/create-a-lobby).

For more information on processing asynchronous operations, see [Asynchronous operations and notifications](/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async).

## Next steps

* [Find and join a lobby](/services/playfab/multiplayer/lobby/join-lobbies)
* [Invite another player to a lobby](/services/playfab/multiplayer/lobby/lobby-invites)
* [Use lobby properties to coordinate a game session](/services/playfab/multiplayer/lobby/lobby-properties)

## See also

* [Create a Lobby](/services/playfab/multiplayer/lobby/create-a-lobby)
* [Asynchronous operations and notifications](/services/playfab/multiplayer/lobby/lobby-and-matchmaking-client-sdk-async)
* [Create searchable lobbies](/services/playfab/multiplayer/lobby/define-search-keywords)
* [Lobby properties](/services/playfab/multiplayer/lobby/lobby-properties)
* [Lobby SDK reference](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/pflobby_members)
* [Lobby SDKs](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-sdks)
* [Matchmaking SDK quickstart](/services/playfab/multiplayer/matchmaking/quickstart-client-sdk)


## Related topics

- [Matchmaking SDK quickstart](/services/playfab/multiplayer/matchmaking/quickstart-client-sdk.md)
- [PlayFab Lobby and Matchmaking SDKs](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/lobby-matchmaking-sdks.md)
- [Integrate Party with Lobby using Multiplayer SDK](/services/playfab/multiplayer/networking/party-lobby-integration.md)
- [Quickstart](/services/playfab/economy-monetization/economy-v2/quickstart.md)
- [Multiplayer Unity plugin quickstart](/services/playfab/multiplayer/lobby/lobby-matchmaking-sdks/multiplayer-unity-plugin-quickstart.md)
