若要在遊戲中使用 Gaming Runtime 功能,請先叫用 XGameRuntimeInitialize 函式來初始化 Gaming Runtime。當您的遊戲使用完 Gaming Runtime 並準備結束時,請叫用 XGameRuntimeUninitialize 函式來取消初始化 Gaming Runtime。請盡可能延後 (但在遊戲結束之前) 叫用 XGameRuntimeUninitialize 函式,通常是在遊戲的進入點函式中。下列範例示範如何在以 Visual Studio 中 Direct3D 12 Desktop Game 範本為基礎之遊戲的進入點函式內,使用 XGameRuntimeInitialize 和 XGameRuntimeUninitialize 函式。XGameRuntimeInitialize 函式會在 Game 物件具現化並註冊之前叫用,而 XGameRuntimeUninitialize 函式會在 Game 物件重設之後、進入點函式傳回之前叫用。
// Entry pointint 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;}