> ## 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)](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-manage-and-license-optional-packages)。

*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**；否则返回错误代码。有关错误代码列表，请参阅[错误代码](/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 中进行相应声明。有关可共享永久本地存储的更多详细信息，请参阅[本地存储](/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](/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members)\
[如何使用新的 MicrosoftGame.config 文件](/build/core-features/common/game-config/MicrosoftGameConfig-toc)\
[本地存储](/build/console-features/storage/local-storage)
