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

# XPersistentLocalStorageMountForPackage

> XPersistentLocalStorageMountForPackage

# XPersistentLocalStorageMountForPackage

將指定套件的永續性本機儲存體 (PLS) 掛接為唯讀磁碟。

## 語法

```cpp theme={null}
HRESULT XPersistentLocalStorageMountForPackage (   
         const char* packageIdentifier,   
         XPackageMountHandle* mountHandle 
) 
```

### 參數

*packageIdentifier*   \_In\_\
類型：char\*

唯一識別 PLS 所屬之市集套件的字串。如需套件識別碼的詳細資訊，請參閱[管理可下載內容 (DLC) 及其授權](/zh-TW/publishing/xstore-commerce/xstore-dlc)。

*mountHandle*   \_Out\_writes\_to\_(pathSize,*pathUsed)\
類型：XPackageMountHandle*

已掛接 PLS 之磁碟的掛接控制代碼。

### 傳回值

類型：[HRESULT](https://learn.microsoft.com/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)

如果成功，則傳回 **S\_OK**；否則傳回錯誤碼。如需錯誤碼的清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。如果函式因指定遊戲的 PLS 不存在而失敗，則會設為 **FILE\_NOT\_FOUND**。如果函式因嘗試存取未啟用可共用永續性本機儲存體之遊戲的 PLS 而失敗，則會得到 **ACCESS\_DENIED**。

## 備註

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

若要讓遊戲支援可共用的 PLS，必須在 MicrosoftGame.config 中如此宣告。如需可共用永續性本機儲存體的詳細資訊，請參閱[本機儲存體](/zh-TW/build/console-features/storage/local-storage)

<Note>如果遊戲將 PLS 標示為可共用，則應確保在暫停遊戲之前，關閉其 PLS 的所有控制代碼，否則遊戲暫停將會失敗，而遊戲將會終止。</Note>

下列程式碼片段示範存取另一個遊戲之可共用 PLS 的範例。

```cpp theme={null}

HRESULT MountPersistentLocalStorageForPackage(char* packageIdentifier) 
{      
    XPackageMountHandle* mountHandle; 
    HRESULT hr = XPersistentLocalStorageMountForPackage (packageIdentifier, &mountHandle); 

    if (FAILED(hr)) return hr; 
    size_t pathSize; 
    hr = XGetMountPathSize(mountHandle, &pathSize); 
    if (FAILED(hr)) 
    { 
        XPackageCloseMountHandle(mountHandle); 
        return hr; 
    } 
 
    char* path = new (std::nothrow) char[pathSize]; 
    if (path == nullptr) 
    { 
        XPackageCloseMountHandle (mountHandle); 
        return E_OUTOFMEMORY; 
    } 
 
    hr = XPackageGetMountPath (mountHandle, pathSize, path); 
    if (FAILED(hr)) 
    { 
        XPackageCloseMountHandle(mountHandle); 
        delete[] path; 
        return hr; 
    } 
 
    printf("PLS %s mounted at path %s\n", packageIdentifier, path); 
    delete[] path; 
 
    // Unmounts PLS path if this is the last handle 
    // to it. 
    XPackageCloseMountHandle(mountHandle); 
    return S_OK; 
} 

```

## 需求

**標頭：** XPersistentLocalStorage.h

**程式庫：** xgameruntime.lib

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

## 概念文件

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

## 另請參閱

[XPersistentLocalStorage](/zh-TW/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members)\
[如何使用新的 MicrosoftGame.config 檔案](/zh-TW/build/core-features/common/game-config/MicrosoftGameConfig-toc)\
[本機儲存體](/zh-TW/build/console-features/storage/local-storage)


## Related topics

- [XPersistentLocalStorageMountForPackage](/reference/system/xpersistentlocalstorage/functions/xpersistentlocalstoragemountforpackage.md)
- [XPersistentLocalStorage](/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members.md)
