> ## 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 o Gaming Runtime.

## Sintaxe

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

### Parâmetros

Nenhum.

### Valor retornado

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

Retornará **S\_OK** se for bem-sucedido; caso contrário, retornará um código de erro. Para obter uma lista de códigos de erro, consulte [Códigos de erro](/pt-BR/reference/errorcodes). Se a função falhar porque a biblioteca do Gaming Runtime (xgameruntime.dll) não foi encontrada, o valor retornado será definido como **E\_GAMERUNTIME\_DLL\_NOT\_FOUND**.

## Comentários

Para usar os recursos do Gaming Runtime em seu jogo, primeiro inicialize o Gaming Runtime invocando a função **XGameRuntimeInitialize**. Invoque a função **XGameRuntimeInitialize** o mais cedo possível, normalmente dentro da função de ponto de entrada do seu jogo. Da mesma forma, cancele a inicialização do Gaming Runtime o mais tarde possível, mas antes de o jogo ser encerrado, invocando a função [XGameRuntimeUninitialize](/pt-BR/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize).

Cada binário compilado e vinculado ao runtime do jogo deve chamar **XGameRuntimeInitialize** no início da inicialização.  Isso inclui o binário do jogo e qualquer middleware em forma de dll que use recursos do Gaming Runtime.  Internamente à função **XGameRuntimeInitialize**, as versões de todas as interfaces com as quais o título foi compilado são verificadas e usadas para inicializar os serviços de runtime correspondentes.  Entre duas versões diferentes do Gaming Runtime, funções podem ser adicionadas ou removidas ou, em casos raros, ter alterações de comportamento significativas.  Chamar **XGameRuntimeInitialize** a partir de cada componente ajudará a detectar problemas de configuração de build, como a compilação com duas versões diferentes e incompatíveis do runtime do jogo por dois binários diferentes que serão carregados no mesmo processo.  Essas configurações incompatíveis resultam em um erro **E\_GAMERUNTIME\_VERSION\_MISMATCH**.

O exemplo a seguir demonstra como usar as funções **XGameRuntimeInitialize** e [XGameRuntimeUninitialize](/pt-BR/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize) dentro da função de ponto de entrada de um jogo baseado no modelo **Direct3D 12 Desktop Game** no Visual Studio. A função **XGameRuntimeInitialize** é invocada antes de o objeto **Game** ser instanciado e registrado, e a função **XGameRuntimeUninitialize** é invocada depois que o objeto **Game** é redefinido, mas antes que a função de ponto de entrada retorne.

```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

**Cabeçalho:** XGameRuntimeInit.h

**Biblioteca:** xgameruntime.lib

**Plataformas com suporte:** Windows, consoles da família XBOX One e consoles XBOX Series

## Documentação conceitual

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

## Confira também

[XGameRuntimeUninitialize](/pt-BR/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize)\
[XGameRuntimeInitializeWithOptions](/pt-BR/reference/system/xgameruntimeinit/functions/xgameruntimeinitializewithoptions)\
[XGameRuntimeInit](/pt-BR/reference/system/xgameruntimeinit/xgameruntimeinit_members)\
[Estruturas de XGameRuntime](/pt-BR/reference/system/xgameruntimeinit/Structures/xgameruntimeoptions)\
[Enumerações de XGameRuntime](/pt-BR/reference/system/xgameruntimeinit/Enumerations/xgameruntimegameconfigsource)\
[Desenvolvendo novos títulos usando o Gaming Runtime](/pt-BR/build/gdk-and-engines/guides/gdk-project-templates)


## Related topics

- [XGameRuntimeInitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeinitialize.md)
- [XGameRuntimeInitializeWithOptions](/reference/system/xgameruntimeinit/functions/xgameruntimeinitializewithoptions.md)
- [XGameRuntimeUninitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize.md)
- [XGameRuntimeInit](/reference/system/xgameruntimeinit/xgameruntimeinit_members.md)
