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

Gaming Runtime を初期化します。

## Syntax

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

### Parameters

なし。

### Return value

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

成功した場合は **S\_OK** を返します。それ以外の場合はエラー コードを返します。エラー コードの一覧については、[エラー コード](/reference/errorcodes)を参照してください。Gaming Runtime ライブラリ (xgameruntime.dll) が見つからなかったために関数が失敗した場合、戻り値は **E\_GAMERUNTIME\_DLL\_NOT\_FOUND** に設定されます。

## Remarks

ゲームで Gaming Runtime 機能を使用するには、まず **XGameRuntimeInitialize** 関数を呼び出して Gaming Runtime を初期化します。**XGameRuntimeInitialize** 関数は、通常はゲームのエントリ ポイント関数内で、できるだけ早い段階で呼び出します。同様に、Gaming Runtime の初期化解除は、ゲームが終了する前のできるだけ遅い段階で、[XGameRuntimeUninitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize) 関数を呼び出して行います。

ゲーム ランタイムに対してコンパイルおよびリンクする各バイナリは、起動の早い段階で **XGameRuntimeInitialize** を呼び出す必要があります。これには、ゲーム バイナリと、Gaming Runtime 機能を使用する DLL 形式のミドルウェアが含まれます。**XGameRuntimeInitialize** 関数の内部では、タイトルがコンパイル時に使用したすべてのインターフェイスのバージョンがチェックされ、対応するランタイム サービスの初期化に使用されます。Gaming Runtime の 2 つの異なるバージョン間では、関数が追加、削除、またはまれに互換性のない動作変更が行われる場合があります。各コンポーネントから **XGameRuntimeInitialize** を呼び出すことにより、同じプロセス内で読み込まれる 2 つの異なるバイナリが、互換性のない異なるバージョンのゲーム ランタイムに対してコンパイルされているようなビルド構成の問題を検出しやすくなります。このような互換性のない構成は、**E\_GAMERUNTIME\_VERSION\_MISMATCH** エラーになります。

次の例は、Visual Studio の **Direct3D 12 Desktop Game** テンプレートに基づくゲームのエントリ ポイント関数で **XGameRuntimeInitialize** および [XGameRuntimeUninitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize) 関数を使用する方法を示します。**XGameRuntimeInitialize** 関数は **Game** オブジェクトのインスタンス化と登録の前に呼び出され、**XGameRuntimeUninitialize** 関数は **Game** オブジェクトがリセットされた後、エントリ ポイント関数が返される前に呼び出されます。

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

## Requirements

**ヘッダー:** XGameRuntimeInit.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## Conceptual documentation

* [What is the Microsoft Game Development Kit?](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/intro/introduction)

## See also

[XGameRuntimeUninitialize](/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize)\
[XGameRuntimeInitializeWithOptions](/reference/system/xgameruntimeinit/functions/xgameruntimeinitializewithoptions)\
[XGameRuntimeInit](/reference/system/xgameruntimeinit/xgameruntimeinit_members)\
[XGameRuntime Structures](/reference/system/xgameruntimeinit/Structures/xgameruntimeoptions)\
[XGameRuntime Enumerations](/reference/system/xgameruntimeinit/Enumerations/xgameruntimegameconfigsource)\
[Developing new titles using Gaming Runtime](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/pc-dev/overviews/gr-developing-new-titles-on-gamecore)


## Related topics

- [XGameRuntimeInitializeWithOptions](/ja-jp/reference/system/xgameruntimeinit/functions/xgameruntimeinitializewithoptions.md)
- [XGameRuntimeUninitialize](/ja-jp/reference/system/xgameruntimeinit/functions/xgameruntimeuninitialize.md)
- [XGameRuntimeInit](/ja-jp/reference/system/xgameruntimeinit/xgameruntimeinit_members.md)
- [XSystemGetRuntimeInfo](/ja-jp/reference/system/xsystem/functions/xsystemgetruntimeinfo.md)
- [XSystemDeviceType](/ja-jp/reference/system/xsystem/enums/xsystemdevicetype.md)
