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

# XPersistentLocalStorageGetPath

> XPersistentLocalStorageGetPath

# XPersistentLocalStorageGetPath

デバイス上の永続ローカル ストレージ (PLS) へのゲーム固有のパスを返します。

## Syntax

```cpp theme={null}
HRESULT XPersistentLocalStorageGetPath(  
         size_t pathSize,  
         char* path,  
         size_t* pathUsed  
)  
```

### Parameters

*pathSize*   \_In\_\
型: size\_t

PLS パス用に用意されたバッファーの文字数。この値を取得するには、[XPersistentLocalStorageGetPathSize](/reference/system/xpersistentlocalstorage/functions/xpersistentlocalstoragegetpathsize) を呼び出します。

*path*   \_Out\_writes\_to\_(pathSize,*pathUsed)\
型: char*

ゲームがデータを書き込むことができる PLS パス。

*pathUsed*   \_Out\_opt\_\
型: size\_t\*

指定したバッファーに書き込まれた文字数。

### Return value

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

成功した場合は **S\_OK** を返します。そうでない場合はエラー コードを返します。エラー コードの一覧については、[エラー コード](/reference/errorcodes) を参照してください。*pathSize* が PLS パスの長さより短いために関数が失敗した場合、戻り値は XBOX デバイスでは **E\_FAIL** に、PC デバイスでは **HRESULT\_FROM\_WIN32(ERROR\_INSUFFICIENT\_BUFFER)** に設定されます。

## Remarks

<Note>この関数はタイム センシティブ スレッドで呼び出すのは安全ではありません。詳細については、[タイム センシティブ スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads) を参照してください。</Note>

ゲームでは、ステージング スペース、ゲーム内 DLC、コンテンツのオンデマンド生成などのタスクのために PLS が必要になる場合があります。この領域はゲームの起動間で保持されますが、ユーザーによって削除されることもあります。PLS の詳細については、[ローカル ストレージ](/build/console-features/storage/local-storage) を参照してください。

PLS はデバイスのファミリーに応じてアクセスおよび管理されます。XBOX デバイスの場合、ドライブのルートにマウントされたフォルダーへのアクセスを提供します。そのフォルダー用にプロビジョニングされるストレージ領域の量は、ゲームの MicrosoftGame.config ファイルで指定されます。プロビジョニングされた領域は、ゲームの起動中は常に利用可能です。空き容量を確保するために、ゲームが実行されていないときに、ユーザーはゲームをアンインストールせずにプロビジョニングされた領域を削除できますが、ゲームが実行中の場合はストレージの可用性が保証されます。XBOX デバイス用にこの領域をプロビジョニングするには、MicrosoftGame.config ファイルに対応するエントリが必要です。

PC デバイスの場合、PC 上のローカル ストレージ フォルダーの場所へのアクセスを提供しますが、ゲーム用に領域が特別にプロビジョニングされるわけではありません。ユーザーは、ゲームが実行中でもその領域を削除できます。ストレージの可用性は保証されず、ストレージ領域を要求するために MicrosoftGame.config ファイルにエントリを追加する必要はありません。まず、ローカル ストレージ フォルダー内の利用可能な領域がゲームの用途に十分であることを確認する必要があります。

PLS パスを取得するためにこの関数を呼び出す前に、[XPersistentLocalStorageGetPathSize](/reference/system/xpersistentlocalstorage/functions/xpersistentlocalstoragegetpathsize) 関数を呼び出して PLS パスの文字数を取得し、その値を *pathSize* パラメーターに指定して、*path* パラメーターにも少なくとも同じ数の文字数を割り当てます。PLS パスに含まれる文字数より少ない文字数が *pathSize* に指定されている場合、エラーが発生します。

次の例は、**XPersistentLocalStorageGetPathSize** および **XPersistentLocalStorageGetPath** 関数を使用してゲームの PLS パスを取得する方法を示しています。

```cpp theme={null}
// 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;
}
```

## Requirements

**ヘッダー:** XPersistentLocalStorage.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## Conceptual documentation

* [XBOX 本体のローカル ストレージ](/build/console-features/storage/local-storage)
* [タイム センシティブ スレッド](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## See also

[XPersistentLocalStorageGetPathSize](/reference/system/xpersistentlocalstorage/functions/xpersistentlocalstoragegetpathsize)\
[XPersistentLocalStorage](/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members)\
[新しい MicrosoftGame.config ファイルの使用方法](/build/core-features/common/game-config/MicrosoftGameConfig-toc)


## Related topics

- [XPersistentLocalStorageGetPathSize](/ja-jp/reference/system/xpersistentlocalstorage/functions/xpersistentlocalstoragegetpathsize.md)
- [XPersistentLocalStorage](/ja-jp/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members.md)
- [GDK 向け Unity C# API ラッパー](/ja-jp/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XPersistentLocalStorageGetSpaceInfo](/ja-jp/reference/system/xpersistentlocalstorage/functions/xpersistentlocalstoragegetspaceinfo.md)
- [XPersistentLocalStorageMountForPackage](/ja-jp/reference/system/xpersistentlocalstorage/functions/xpersistentlocalstoragemountforpackage.md)
