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

# Save

> 将数据保存到指定容器中的指定 Blob（文件）。

# Microsoft.Xbox.Wrappers.XGameSave.Provider.Save

将数据保存到指定容器中的指定 Blob（文件）。

<a id="syntaxSection" />

## 语法

```cpp theme={null}
HRESULT Save(const std::string& containerName,
             const std::string& blobName,
             size_t dataSize,
             const uint8_t* blobData);
```

<a id="parametersSection" />

### 参数

*containerName*   \_In\_<br />类型：std::string

容器的名称。

*blobName*  \_In\_<br />类型：std::string

Blob 的名称。

*dataSize*   \_In\_<br />类型：size\_t

要写入 Blob 的数据量。此大小的上限为 16 MB（GS\_MAX\_BLOB\_SIZE）。

*blobData*   \_In\_<br />类型：uint8\_t\*

指向要写入 Blob 的字节的指针。

<a id="retvalSection" />

### 返回值

类型：HRESULT

此方法在成功时返回 **S\_OK**，在失败时返回以下 HRESULT 代码：

* **GS\_INVALID\_CONTAINER\_NAME**
* **GS\_OUT\_OF\_LOCAL\_STORAGE**
* **GS\_UPDATE\_TOO\_BIG**
* **GS\_QUOTA\_EXCEEDED**
* **GS\_HANDLE\_EXPIRED**

<a id="exampleSection" />

## 示例

以下代码示例演示了如何使用 **Save** 函数。

```cpp theme={null}
using Microsoft::Xbox::Wrappers::GameSave;

std::vector<uint8_t> saveData; // Contains the player's data.

Provider provider = new Provider();

if(SUCCEEDED(provider->Initialize(userHandle, mySCID))
{  
   HRESULT hr = provider->Save("Save_slot_1", "progress", saveData.size(), saveData.data());
   if(FAILED(hr))
   {
      if(hr == E_GS_QUOTA_EXCEEDED)
      {
         // Message that the user must delete saves for this game.
      }
      else if(hr == E_GS_OUT_OF_LOCAL_STORAGE)
      {
         // Message to the user that they have run out of save
         // space on the local device.
      }
      else if(hr == E_GS_UPDATE_TOO_BIG)
      {
         // This is really a development time thing to catch.
         // Your save size was too large for this Save call. Save
         // calls are limited to a maximum size of
         // 16 MB (GS_MAX_BLOB_SIZE).
      }
      else if(hr == E_GS_HANDLE_EXPIRED)
      {
         // You must recreate the provider, and then try again.
      }
      else
      {
         // Log error.
      }
   }
}
```

<a id="remarksSection" />

## 备注

必须先调用 [Initialize](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize) 方法，然后才能调用 `Provider` 类中的任何其他方法。

若要初始化保存游戏包装器并同步指定用户的所有容器，请调用 [Initialize](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize)。

若要从指定容器中的给定 Blob 加载数据，请调用 [Load](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load)。

<a id="requirementsSection" />

## 要求

**标头：** xgamesavewrappers.hpp

**支持的平台：** Windows、XBOX One 系列主机和 XBOX Series 主机

<a id="seealsoSection" />

## 另请参阅

[Microsoft.Xbox.Wrappers.XGameSave.Provider](/reference/system/Wrappers/classes/provider/xgamesave_wrapper_provider)<br />[XGameSave 包装器成员](/reference/system/Wrappers/xgamesave_wrapper_members)<br />[Load](/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load)


## Related topics

- [XGameSave](/zh-CN/reference/system/xgamesave/xgamesave_members.md)
- [Game Saves 限制](/zh-CN/services/playfab/player-progression/game-saves/limits.md)
- [Game Saves 冲突](/zh-CN/services/playfab/player-progression/game-saves/conflicts.md)
- [XGameSaveBlob](/zh-CN/reference/system/xgamesave/structs/xgamesaveblob.md)
- [XGameSaveFiles](/zh-CN/reference/system/xgamesavefiles/xgamesavefiles_members.md)
