// 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 Games 会提示用户购买游戏。对于其他错误,仍建议尽快退出游戏进程,因为该进程无法使用 SDK 执行关键操作,例如验证用户是否拥有游戏的有效许可。
如果响应不成功,可能表示存在以下情况之一:
SDK 运行时未安装、未在设备上运行,或者版本较旧,与集成到游戏中的 SDK 不兼容。
SDK 运行时无法验证游戏的应用身份。这可能是因为 manifest.xml 无效,或者在开发时使用了 SDK 但未启用开发者模式。如果没有此设置,则必须使用注册到您的 Play 软件包名称的数字证书对游戏的可执行文件进行数字签名。
游戏可执行文件不是通过 Google Play 游戏客户端启动的。
Google Play Games 中的活跃用户没有相应应用的许可。
第 5 步:(可选)支持多个游戏进程
如果您的游戏使用多个进程,并计划从并非由 Google Play Games for PC 直接启动的进程中使用 Play Games PC SDK,则需要执行额外的集成步骤:
在此示例中,我们看到一个进程层次结构,其中 Google Play Games 电脑版 (GooglePlayGames.exe) 使用一些示例参数 (--foo=abc --bar=123) 启动游戏 (YourGameLauncher.exe)。然后,游戏会生成一个使用 Play Games 电脑版 SDK 的子进程 (YourGame.exe)。为了实现这一点,Google Play Games 电脑版启动的游戏进程会将收到的命令行参数转发给子进程。
当游戏停止运行时,退出所有进程。
当用户关闭游戏或游戏因 SDK 初始化失败(例如 kActionRequiredShutdownClientProcess)而退出时,请关闭游戏生成的所有进程。这样可确保下次 Google Play Games 电脑版客户端启动游戏时,新更改(例如切换到其他有效账号)会生效。
[[["易于理解","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"]],["最后更新时间 (UTC):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)"]]