XPersistentLocalStorageGetPathSize

返回指向永久性本地存储 (PLS) 的路径的长度(字符数)。

语法

HRESULT XPersistentLocalStorageGetPathSize(  
         size_t* pathSize  
)  

参数

pathSize _Out_
类型:size_t*

PLS 路径的长度(字节数)。

返回值

类型:HRESULT

如果成功,则返回 S_OK;否则返回错误代码。 有关错误代码的列表,请参阅错误代码

备注

注意

在时间敏感线程上调用此函数是不安全的。 有关详细信息,请参阅时间敏感线程

此函数的返回值用于 XPersistentLocalStorageGetPath 函数的 pathSize 参数,以返回设备上特定于游戏的 PLS 路径。 有关 PLS 的详细信息,请参阅本地存储

当调用 XPersistentLocalStorageGetPath 函数时,为 XPersistentLocalStorageGetPathpath 参数分配的字符数应至少与在此函数的 pathSize 参数中返回的值中指定的字符数一样多;否则将导致错误。

下面的示例说明如何使用 XPersistentLocalStorageGetPathSizeXPersistentLocalStorageGetPath 函数获取游戏的 PLS 路径。

// Confirm that all of the features needed to run asynchronous tasks on 
// task queues are available.
LPCSTR Game::CheckPLSPath()
{
    // Confirm the length of the path to the local storage folder.
    LPCSTR returnPath = "";
    size_t pathSize;
    if (SUCCEEDED(XPersistentLocalStorageGetPathSize(&pathSize)))
    {
        char * path = new char[pathSize];
        size_t * pathUsed = new size_t;
        if (path != nullptr)
        {
            // Get the path to the local storage folder.
            if (SUCCEEDED(XPersistentLocalStorageGetPath(pathSize, path, pathUsed))) 
            {
                // Just to be safe, copy the bytes used in the buffer 
                // to a separate string.
                char * actualPath = new char[*pathUsed];
                strncpy(actualPath, path, *pathUsed);
                returnPath = actualPath;
            }
        }
    };

    return returnPath;
}

要求

头文件:XPersistentLocalStorage.h

库:xgameruntime.lib

支持平台:Windows、Xbox One 系列主机和 Xbox Series 主机

另请参阅

XPersistentLocalStorageGetPath
XPersistentLocalStorage
如何使用新的 MicrosoftGame.config 文件