> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Save

> XGameSave 包裝函式 Provider.Save 方法的參考資料，此方法會將遊戲狀態位元組寫入指定存檔容器內的具名 Blob (檔案)。

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

將資料儲存到指定容器內的指定 Blob (檔案)。

## 語法

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

### 參數

*containerName*   \_In\_\
類型：std::string

容器的名稱。

*blobName*  \_In\_\
類型：std::string

Blob 的名稱。

*dataSize*   \_In\_\
類型：size\_t

要寫入 Blob 的資料量。此大小上限為 16 MB (GS\_MAX\_BLOB\_SIZE)。

*blobData*   \_In\_\
類型：uint8\_t\*

指向要寫入 Blob 之位元組的指標。

### 傳回值

類型：HRESULT

此方法成功時會傳回 **S\_OK**，失敗時則會傳回下列 HRESULT 代碼：

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

## 範例

下列程式碼範例示範如何使用 **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.
      }
   }
}
```

## 備註

您必須先呼叫 [Initialize](https://docs.xbox.com/zh-TW/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize.md) 方法，才能呼叫 `Provider` 類別中的任何其他方法。

若要初始化遊戲存檔包裝函式，並同步處理指定使用者的所有容器，請呼叫 [Initialize](https://docs.xbox.com/zh-TW/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_initialize.md)。

若要從指定容器中的指定 Blob 載入資料，請呼叫 [Load](https://docs.xbox.com/zh-TW/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load.md)。

## 需求

**標頭：** xgamesavewrappers.hpp

**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[Microsoft.Xbox.Wrappers.XGameSave.Provider](https://docs.xbox.com/zh-TW/reference/system/Wrappers/classes/provider/xgamesave_wrapper_provider.md)\
[XGameSave 包裝函式成員](https://docs.xbox.com/zh-TW/reference/system/Wrappers/xgamesave_wrapper_members.md)\
[Load](https://docs.xbox.com/zh-TW/reference/system/Wrappers/classes/provider/methods/xgamesave_wrapper_provider_load.md)


## Related topics

- [Game Saves 工具](https://docs.xbox.com/zh-TW/build/core-features/common/game-save/game-saves-tools.md)
- [Game Saves 偵錯](https://docs.xbox.com/zh-TW/build/core-features/common/game-save/game-saves-debugging.md)
- [Game Saves 概觀](https://docs.xbox.com/zh-TW/build/core-features/common/game-save/game-saves-overview.md)
- [Game Saves (內容)](https://docs.xbox.com/zh-TW/build/core-features/common/game-save/game-saves-toc.md)
- [Game Saves 回復](https://docs.xbox.com/zh-TW/services/playfab/player-progression/game-saves/rollback.md)
