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

# XGameSaveGetContainerInfo

> XGameSaveGetContainerInfo

# XGameSaveGetContainerInfo

擷取 **XGameSaveProvider** 中容器的資訊。

## 語法

```cpp theme={null}
HRESULT XGameSaveGetContainerInfo(  
         XGameSaveProviderHandle provider,  
         const char* containerName,  
         void* context,  
         XGameSaveContainerInfoCallback* callback  
)  
```

### 參數

*provider*   \_In\_\
類型：XGameSaveProviderHandle

包含所需容器的 **XGameSaveProvider** 控制代碼。

*containerName*   \_In\_z\_\
類型：char\*

要擷取資訊的容器名稱，若找到則只會傳回一個結果。如果需要多個容器，請使用 [XGameSaveEnumerateContainerInfo](/zh-TW/reference/system/xgamesave/functions/xgamesaveenumeratecontainerinfo) 或 [XGameSaveEnumerateContainerInfoByName](/zh-TW/reference/system/xgamesave/functions/xgamesaveenumeratecontainerinfobyname)。

*context*   \_In\_opt\_\
類型：void\*

作為內容的呼叫物件指標。

*callback*   \_In\_\
類型：XGameSaveContainerInfoCallback\*

用來判斷 [XGameSaveContainerInfo](/zh-TW/reference/system/xgamesave/structs/xgamesavecontainerinfo) 呼叫結果並從中收集資料的回呼函式。

### 傳回值

類型：HRESULT

函式結果

#### 常見錯誤

* E\_GS\_INVALID\_CONTAINER\_NAME
* E\_GS\_USER\_CANCELED
* E\_GS\_CONTAINER\_NOT\_IN\_SYNC
* E\_GS\_CONTAINER\_SYNC\_FAILED
* E\_GS\_HANDLE\_EXPIRED

## 備註

<Note>在時間敏感執行緒上呼叫此函式並不安全。如需詳細資訊，請參閱[時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)。</Note>

容器是中繼資料的集合，也是其中 Blob 集合的參考點。如果事先知道容器名稱，就可以使用此 API 只傳回該容器的資訊。這對於取回玩家的特定資訊很有用，不必在每次需要資訊時都要求所有資訊。您可以在 [XGameSaveContainerInfo](/zh-TW/reference/system/xgamesave/structs/xgamesavecontainerinfo) 結構中找到 **XGameSaveContainer** 的組成。

```cpp theme={null}
void Sample::_GetContainerInfo(const char* name) 
{ 
    XGameSaveContainerInfoCallback* callback = [](_In_ const XGameSaveContainerInfo* info, _In_ void* ctx) -> bool 
    { 
        auto self = reinterpret_cast<Sample*>(ctx); 
        self->_UpdateContainerList(info); 
        return true; 
    }; 
  
    HRESULT hr = XGameSaveGetContainerInfo(_provider, name, this, callback); 
    if (FAILED(hr)) 
    { 
        _HandleContainerErrors(name, hr); 
    } 
} 
 
void Sample::_UpdateContainerList(const XGameSaveContainerInfo* container) 
{ 
    //update UX 
    printf("%s - %s: %I64dbytes %d blobs\n", container->name, container->displayName, container->totalSize, container->blobCount); 
    if (strcmp(container->name, "AutoSave") == 0) 
    { 
        _ReadContainerBlobsAsync(container); 
    } 
} 
 
void Sample::_HandleContainerErrors(const char* name, HRESULT hr) 
{ 
    switch (hr) 
    { 
    case E_GS_INVALID_CONTAINER_NAME: 
        printf("\'%s\' name is invalid for a container", name); 
        break; 
    case E_GS_USER_CANCELED: 
        printf("Container %s failed to sync user canceled hr=0x%08x\n", name, hr); 
        break; 
    case E_GS_CONTAINER_NOT_IN_SYNC: 
    case E_GS_CONTAINER_SYNC_FAILED: 
        printf("Container %s failed to sync hr=0x%08x\n", name, hr); 
        break; 
    case E_GS_HANDLE_EXPIRED: 
        printf("Container %s failed, re-initialize provider", name); 
        break; 
    case S_OK: 
        break; 
    default: 
        printf("Unknown Container error %s hr=0x%08X\n", name, hr); 
    } 
}
```

## 需求

**標頭：** XGameSave.h

**程式庫：** xgameruntime.lib

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

## 概念文件

* [時間敏感執行緒](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 另請參閱

[XGameSave](/zh-TW/reference/system/xgamesave/xgamesave_members)\
[XGameSaveCreateContainer](/zh-TW/reference/system/xgamesave/functions/xgamesavecreatecontainer)\
[XGameSaveContainerInfo](/zh-TW/reference/system/xgamesave/structs/xgamesavecontainerinfo)\
[偵錯遊戲存檔](/zh-TW/build/core-features/common/game-save/game-saves-debugging)


## Related topics

- [XGameSaveGetContainerInfo](/reference/system/xgamesave/functions/xgamesavegetcontainerinfo.md)
- [XGameSaveContainerInfoCallback](/reference/system/xgamesave/functions/xgamesavecontainerinfocallback.md)
