// Initialize the SDK as part of the startup sequence of your application.autopromise=std::make_shared<std::promise<InitializeResult>>();GooglePlayInitialize([promise](InitializeResultresult){promise->set_value(std::move(result));});autoinitialize_result=promise->get_future().get();if(initialize_result.ok()){// The SDK succeeded with initialization. Continue with the startup sequence// of the game.// ...}elseif(initialize_result.code()==InitializationError::kActionRequiredShutdownClientProcess){// The SDK failed to initialize and has requested that your game process exit// as soon as possible.exit(1);}else{// The SDK failed to initialize for an alternative reason. It is still// generally recommended that you exit the game process as soon as possible,// because it won't be possible to access any APIs in the SDK. Critical// operations such as verifying the user owns a valid license to your game// won't be possible.// ...}
如果初始化失敗並顯示 kActionRequiredShutdownClientProcess 代碼,請盡快結束遊戲程序。SDK 的執行階段會嘗試協助使用者,您的遊戲無須採取其他行動。舉例來說,如果使用者沒有遊戲的有效授權,Google Play 遊戲就會提示使用者購買副本。如果發生其他錯誤,我們仍建議盡快結束遊戲程序,因為遊戲無法使用 SDK 執行重要作業,例如驗證使用者是否擁有遊戲的有效授權。
如果回應不成功,可能表示出現下列其中一種情況:
SDK 執行階段未安裝、未在裝置上執行,或版本較舊,與整合至遊戲的 SDK 不相容。
SDK 執行階段無法驗證遊戲的應用程式身分。這可能是因為 manifest.xml 無效,或是在開發時使用 SDK 但未啟用開發人員模式。否則,您必須使用向 Play 套件名稱註冊的數位憑證,以數位方式簽署遊戲的可執行檔。
遊戲可執行檔並非透過 Google Play 遊戲用戶端啟動。
Google Play 遊戲中的活躍使用者沒有應用程式授權。
步驟 5:(選用) 支援多個遊戲程序
如果遊戲使用多個程序,並打算從 Google Play 遊戲電腦版未直接啟動的程序使用 Play 遊戲電腦版 SDK,則需要採取額外的整合步驟:
在這個範例中,我們看到程序階層,其中 Google Play 遊戲電腦版 (GooglePlayGames.exe) 會啟動遊戲 (YourGameLauncher.exe) 並提供一些範例參數 (--foo=abc --bar=123)。接著,遊戲會產生子程序 (YourGame.exe),該程序會使用 Play 遊戲電腦版 SDK。如要允許這項操作,Google Play 遊戲電腦版啟動的遊戲程序會將收到的命令列參數轉送至子程序。
遊戲停止執行時,結束所有程序。
當使用者關閉遊戲,或遊戲因 SDK 初始化失敗 (例如 kActionRequiredShutdownClientProcess) 而結束時,請關閉遊戲產生的所有程序。這樣一來,下次透過 Google Play 遊戲電腦版用戶端啟動遊戲時,系統就會套用新變更,例如切換至其他有效帳戶。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-29 (世界標準時間)。"],[],[],null,["# Power your game using the Play Games PC SDK\n\nWith the Play Games PC SDK you can access Google Play services to build and\nmonetize your game on PCs. Sell digital content using Play Billing, seamlessly\nsign-in using Play Games, and ensure your users have a valid entitlement to your\napplication with Play Integrity.\n\nReady to get started?\n\nPrerequisites\n-------------\n\n- Create an app entry inside of the Play Console and claim a Play package name.\n\n- Download and install\n [Google Play Games for PC](https://play.google.com/googleplaygames) and sign in with\n your Google Account.\n\n**Step 1**: Add the SDK to your project\n---------------------------------------\n\n| **Note:** The SDK officially supports C++. If you are using a programming language other than C++ please reach out to your Google Partner letting them know what game engine \\& programing language your application uses to see if we can better support you.\n\n- Download the [Play Games PC C++ SDK](/games/playgames/native-pc/downloads/cpp).\n\n- Copy the API headers folder `includes/` into your application's codebase.\n\n- Copy the redistributable files from `imports/` into your application's\n project.\n\n - Link your project against `play_pc_sdk.lib` allowing access to the contents of the `play_pc_sdk.dll`.\n\n**Step 2**: Add a manifest file\n-------------------------------\n\nBefore you can use the SDK from within your game you will need to\nassociate your game executable with the Play package name that you claimed\ninside of the Play Console. This done by adding a `manifest.xml` file in the\nsame directory as your game's executable.\n\nExample `manifest.xml` contents: \n\n \u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n \u003cManifest version=\"1\"\u003e\n \u003cApplication\u003e\n \u003cPackageName\u003e\u003cvar translate=\"no\"\u003ecom.example.package\u003c/var\u003e\u003c/PackageName\u003e\n \u003c/Application\u003e\n \u003c/Manifest\u003e\n\nExample `manifest.xml` placement: \n\n C:\\Program Files\n └───Example Game\n ├───Game.exe\n └───manifest.xml\n\n**Step 3**: Digitally sign your game\n------------------------------------\n\n| **Tip:** Developers can skip this step during local development by enabling [developer mode](/games/playgames/native-pc/setup/developer_mode).\n\nBefore your game can use the SDK, the game's executable must be digitally signed\nusing an\n[Authenticode Digital Signature](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/authenticode).\nFor instructions on how to sign an executable see the\n[documentation on the SignTool](https://learn.microsoft.com/en-us/windows/win32/seccrypto/signtool) .\n\n**Step 4**: Initialize the SDK\n------------------------------\n\nInitialize the SDK during the startup sequence of your game. This should be done\nautomatically without requiring any user interaction and it is recommended to\nverify a successful initialization before rendering your game window.\nThis provides the best user experience by surfacing and resolving errors as soon\nas possible and avoids your game window briefly appearing in cases where your\ngame process needs to exit.\n\nStart using the SDK by calling\n[`GooglePlayInitialize`](/games/playgames/native-pc/reference/namespace/google/play/initialization) to initialize the API. This\nwill setup global state, connect with the SDK runtime, and verify the\napplication was started correctly. This **MUST** be called and have the\ncontinuation callback complete with `InitializeResult::ok()` equal to `true`\nbefore any other API may be used. \n\n // Initialize the SDK as part of the startup sequence of your application.\n auto promise = std::make_shared\u003cstd::promise\u003cInitializeResult\u003e\u003e();\n GooglePlayInitialize(\n [promise](InitializeResult result) {\n promise-\u003eset_value(std::move(result));\n });\n\n auto initialize_result = promise-\u003eget_future().get();\n if (initialize_result.ok()) {\n // The SDK succeeded with initialization. Continue with the startup sequence\n // of the game.\n // ...\n } else if (initialize_result.code() == InitializationError::kActionRequiredShutdownClientProcess) {\n // The SDK failed to initialize and has requested that your game process exit\n // as soon as possible.\n exit(1);\n } else {\n // The SDK failed to initialize for an alternative reason. It is still\n // generally recommended that you exit the game process as soon as possible,\n // because it won't be possible to access any APIs in the SDK. Critical\n // operations such as verifying the user owns a valid license to your game\n // won't be possible.\n // ...\n }\n\nIf the initialization fails with the code `kActionRequiredShutdownClientProcess`\n**exit the game process as soon possible**. The SDK's runtime will attempt\nto assist the user with no additional action required by your game. For example\nif the user does not own a valid license to the game, Google Play Games will\nprompt the user to purchase a copy. For other errors it is still recommended to\nexit the game process as soon as possible as it won't to use the SDK to\nperform critical operations such as verifying the user owns a valid license\nto your game.\n\nA non-successful response may indicate one of the following conditions:\n\n- The SDK runtime is not installed, is not running on the device or is\n an older version not compatible with the SDK integrated into your game.\n\n- The SDK runtime was unable to verify the application identity of the\n game. This could be due to an invalid `manifest.xml` or using the SDK\n without enabling [developer mode](/games/playgames/native-pc/setup/developer_mode)\n when developing. Without this your game's executable is required to be\n digitally signed with the digital certificate registered to your Play package\n name.\n\n- The game executable was not launched through the Google Play games client.\n\n- The active user in Google Play Games does not own a license for the\n application.\n\n**Step 5**: (Optional) Supporting multiple game-processes\n---------------------------------------------------------\n\nIf your game uses multiple processes and plans to use the Play Games PC SDK from\na process that is not directly launched by Google Play Games for PC additional\nintegration steps are required:\n\n1. The process directly launched by Google Play Games for PC must\n verify a successful [initialization of the Play Games PC SDK](#step-4).\n\n This provides the best user experience by surfacing errors as soon as\n possible. Note that child-process using the SDK must also perform\n initialization in addition to the directly launched process.\n2. To use the Play Games PC SDK in a child-process forward the command line\n parameters to the spawned child-process.\n\n Example command line parameter forwarding: \n\n Processes hierarchy tree:\n\n GooglePlayGames.exe\n └───YourGameLauncher.exe --foo=abc --bar=123\n └───YourGame.exe --foo=abc --bar=123\n\n In this example we see a process hierarchy where Google Play Games for PC\n (`GooglePlayGames.exe`) launches the game (`YourGameLauncher.exe`) with some\n example parameters (`--foo=abc --bar=123`). The game then spawns a\n child-process (`YourGame.exe`) which uses the Play Games PC SDK. To allow this\n the game process launched by Google Play Games for PC forwards the command\n line parameters it was given to the child-process.\n3. Exit all processes when the game stops running.\n\n When a user closes your game or the game exits due to a SDK initialization\n failure, such as `kActionRequiredShutdownClientProcess`, close all processes\n your game has spawned. This makes certain that the next time your game is\n launched by the Google Play Games for PC client, new changes such as switching\n to a different active account will take effect.\n\nNext steps\n----------\n\nUse the SDK while developing in your IDE:\n\n- Enable [developer mode](/games/playgames/native-pc/setup/developer_mode)\n\nAdd Google Play PC features to your app:\n\n- Sell digital goods with [Play Billing](/games/playgames/native-pc/billing)\n- Measure your marketing with [Play Install Referrer](/games/playgames/native-pc/install_referrer)"]]