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

# Initializing the GDK

> Set up MicrosoftGame.config, initialize the Gaming Runtime and XSAPI, and sign in the user to XBOX Live when porting a title from Steamworks to the GDK.

To start using Steamworks after adding it to your game's project, you need to call the `SteamAPI_Init` function to initialize the API. Optionally, you can call `SteamAPI_RestartAppIfNecessary` to relaunch the app through Steam if necessary. Initializing the XBOX Game Development Kit (GDK) is a bit more involved, because there isn't a unified app used to launch the game and communicate with the different gaming services like there is on Steam.

To start using the APIs in the XBOX Game Development Kit (GDK), you need to use the following steps.

1. Add a *MicrosoftGame.config* file to your project.
2. Initialize the Gaming Runtime service.
3. Initialize the XBOX Services API to make calls to XBOX Live for user identity, cloud saves, achievements, and more.
4. Sign the user in to XBOX Live. Store the handle and XBOX User ID (XUID) that was returned after a successful sign-in for future use.

<Note>
  On Steam, you have access to the user's Steam ID and all the APIs at load time, because the Steam launcher automatically injects the user's account information when games are launched from their service. The XBOX Live APIs are used by games across multiple launchers, so you don't get this for free. You need to manually sign the user in at launch.
</Note>

For information about how to do step 1, see [MicrosoftGame.config overview](/build/core-features/common/game-config/MicrosoftGameConfig-Overview).

You can find information about how to do steps 2–4 in [Getting started with XBOX Live APIs](/services/xbox-services/index) (or summarized as follows), making sure to implement the behavior that's described in the Cleaning up XSAPI section of that topic as well. After the Gaming Runtime and XBOX Services API have been initialized, you can sign the user in to XBOX Live. You don't need to create an `XTaskQueue` because that's automatically created for you if you leave it blank.

```cpp theme={null}
#include <XGameRuntimeInit.h>
#include <XTaskQueue.h>
#include <xsapi-c/services_c.h>

// ...

void InitializeXboxLive()
{
    // ...
    HRESULT hr = XGameRuntimeInitialize();
    if (FAILED(hr))
    {
        // handle error: couldn't initialize the Gaming Runtime service.
    }

    XblInitArgs xblArgs = {};
    xblArgs.scid = "00000000-0000-0000-0000-000000000000"; // Add your SCID here that you got from the Partner Center web portal.

    HRESULT hr = XblInitialize(&xblArgs);
    if (FAILED(hr))
    {
        // handle error: couldn't initialize XBOX Live.
    }
    // ...
}
```

## Sign the user in to XBOX Live

Use the [XUserAddAsync API](/build/core-features/common/user/xuser_howto_best_practice_signing_in) to sign a user in to XBOX Live. If this is the first time they're signing in to your game, they're given a list of privileges that your game is requesting. They'll need to explicitly authorize these privileges to access their XBOX Live account.

After they're successfully signed in, you can use the `XUserHandle` reference that you passed into the [`XUserAddResult`](/reference/system/xuser/xuser_members) function. It can be used to obtain information about that XBOX Live user, such as their gamertag, gamer photo, sign-in state, age group, and privileges.

After the user signs in for the first time, they should be able to successfully sign in silently (that is, with no action required on their part) if they don't need to resolve a UI prompt (such as a new privacy agreement) since they last launched the game. However, you'll still need to make these API calls to gain identity access.

An `XblContextHandle` will be needed to call XBOX Live APIs. You can use the [XblContextCreateHandle](/reference/live/xsapi-c/xbox_live_context_c/xbox_live_context_c_members) function to get an `XblContextHandle` by using an `XUserHandle`.


## Related topics

- [Steam porting guide overview](/build/steam-porting-guide/overview.md)
- [Port from Steam](/paths/porting/from-steam.md)
- [Conceptual differences between the GDK and Steamworks](/build/steam-porting-guide/conceptual-differences.md)
- [PC end-to-end overview](/build/gdk-and-engines/overview.md)
- [XblMultiplayerSessionInitializationInfo](/reference/live/xsapi-c/multiplayer_c/structs/xblmultiplayersessioninitializationinfo.md)
