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

# XGameRuntimeInitialize

> XGameRuntimeInitialize

# XGameRuntimeInitialize

Inicializa Gaming Runtime.

## Sintaxis

```cpp theme={null}
HRESULT XGameRuntimeInitialize(  
)  
```

### Parámetros

Ninguno.

### Valor devuelto

Tipo: [HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

Devuelve **S\_OK** si se realiza correctamente; de lo contrario, devuelve un código de error. Para obtener una lista de códigos de error, consulte [Códigos de error](/reference/errorcodes). Si la función falla porque no se encontró la biblioteca de Gaming Runtime (xgameruntime.dll), el valor devuelto se establece en **E\_GAMERUNTIME\_DLL\_NOT\_FOUND**.

## Comentarios

Para usar las características de Gaming Runtime en su juego, primero inicialice Gaming Runtime invocando la función **XGameRuntimeInitialize**. Invoque la función **XGameRuntimeInitialize** lo antes posible, normalmente dentro de la función de punto de entrada del juego. De forma similar, anule la inicialización de Gaming Runtime lo más tarde posible, pero antes de que el juego se cierre, invocando la función [XGameRuntimeUninitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize).

Cada binario que se compila y vincula con el entorno de ejecución del juego debe llamar a **XGameRuntimeInitialize** al principio del inicio. Esto incluye el binario del juego y cualquier middleware en forma de dll que use características de Gaming Runtime. Internamente, la función **XGameRuntimeInitialize** comprueba las versiones de todas las interfaces con las que se compiló el título y las usa para inicializar los servicios del entorno de ejecución correspondientes. Entre dos versiones diferentes de Gaming Runtime, se pueden agregar o quitar funciones o, en raras ocasiones, puede haber cambios de comportamiento importantes. Llamar a **XGameRuntimeInitialize** desde cada componente ayudará a detectar problemas de configuración de compilación, como compilar con dos versiones diferentes e incompatibles del entorno de ejecución del juego en dos binarios distintos que se cargarán en el mismo proceso. Estas configuraciones incompatibles producen un error **E\_GAMERUNTIME\_VERSION\_MISMATCH**.

En el ejemplo siguiente se muestra cómo usar las funciones **XGameRuntimeInitialize** y [XGameRuntimeUninitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize) dentro de la función de punto de entrada de un juego basado en la plantilla **Direct3D 12 Desktop Game** de Visual Studio. La función **XGameRuntimeInitialize** se invoca antes de crear una instancia del objeto **Game** y registrarlo, y la función **XGameRuntimeUninitialize** se invoca después de restablecer el objeto **Game**, pero antes de que la función de punto de entrada devuelva el control.

```cpp theme={null}
// Entry point
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // Initialize the Gaming Runtime before
    // performing any other activity.
    if (FAILED(XGameRuntimeInitialize()))
        return 1;

    if (!XMVerifyCPUSupport())
        return 1;

    g_game = std::make_unique<Game>();

    // Register class and create window
    {
        // Code omitted for brevity.
        ...
    }

    // Main message loop
    MSG msg = {};
    while (WM_QUIT != msg.message)
    {
        // Code omitted for brevity.
        ...
    }

    g_game.reset();

    // Uninitialize the Gaming Runtime after
    // all other activity has been completed.
    XGameRuntimeUninitialize();

    return (int) msg.wParam;
}
```

## Requisitos

**Encabezado:** XGameRuntimeInit.h

**Biblioteca:** xgameruntime.lib

**Plataformas compatibles:** Windows, consolas de la familia XBOX One y consolas XBOX Series

## Documentación conceptual

* [¿Qué es Microsoft Game Development Kit?](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/intro/introduction)

## Consulte también

[XGameRuntimeUninitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize)\
[XGameRuntimeInitializeWithOptions](/reference/system/xgameruntimeinit/functions/xgameruntimeinitializewithoptions)\
[XGameRuntimeInit](/reference/system/xgameruntimeinit/xgameruntimeinit_members)\
[Estructuras de XGameRuntime](/reference/system/xgameruntimeinit/Structures/xgameruntimeoptions)\
[Enumeraciones de XGameRuntime](/reference/system/xgameruntimeinit/Enumerations/xgameruntimegameconfigsource)\
[Desarrollo de nuevos títulos con Gaming Runtime](/build/gdk-and-engines/guides/gdk-project-templates)


## Related topics

- [XGameRuntimeInitializeWithOptions](/es/reference/system/xgameruntimeinit/functions/xgameruntimeinitializewithoptions.md)
- [XGameRuntimeUninitialize](/es/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize.md)
- [XGameRuntimeInit](/es/reference/system/xgameruntimeinit/xgameruntimeinit_members.md)
- [XSystemGetRuntimeInfo](/es/reference/system/xsystem/functions/xsystemgetruntimeinfo.md)
- [XGameRuntimeIsFeatureAvailable](/es/reference/system/xgameruntimefeature/functions/xgameruntimeisfeatureavailable.md)
