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

# XGameStreamingGetSessionId

> XGameStreamingGetSessionId

# XGameStreamingGetSessionId

この API は、指定されたクライアントのストリーミング セッションを一意に識別する null 終端の不透明な文字列を返します。

## Syntax

```cpp theme={null}
HRESULT XGameStreamingGetSessionId(
        XGameStreamingClientId client,
        size_t sessionIdSize,
        char* sessionId,
        size_t* sessionIdUsed
)
```

### Parameters

*client*   \_In\_\
型: XGameStreamingClientId

照会するストリーミング クライアント。

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

`sessionId` バッファーのサイズ。

*sessionId*   \_Out\_writes\_bytes\_to\_(sessionIdSize, \*sessionIdUsed)\
型: char\*

指定されたクライアントのセッション ID が格納されるバッファー。

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

`sessionId` バッファーに返される値のバイト単位のサイズ (null 終端文字を含む)。

### Return value

型: HRESULT

成功した場合は **S\_OK** を返します。それ以外の場合はエラー コードを返します。

#### 想定されるエラー

| エラー コード                                  | エラー値       | エラーの理由                                                                                                                                                     |
| ---------------------------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| E\_GAMESTREAMING\_NOT\_INITIALIZED       | 0x89245400 | XGameStreaming ランタイムが初期化されていません。他の API を呼び出す前に [XGameStreamingInitialize](/reference/system/xgamestreaming/functions/xgamestreaminginitialize) を呼び出してください。 |
| E\_GAMESTREAMING\_CLIENT\_NOT\_CONNECTED | 0x89245401 | 指定されたクライアントが接続されていません。                                                                                                                                     |
| E\_GAMESTREAMING\_NO\_DATA               | 0x89245402 | 要求されたデータは利用できません。データは後で利用可能になる場合があります。                                                                                                                     |
| E\_NOT\_SUFFICIENT\_BUFFER               | 0x7A       | *sessionId* が、セッション ID と null 終端文字を格納するのに十分な大きさではありません。                                                                                                    |

エラー コードの一覧については、[Error Codes](/reference/errorcodes) を参照してください。

## Remarks

`sessionId` に書き込まれる文字列は `SessionIdMaxBytes` を超えることはないため、事前に割り当てることができます。`sessionId` のレイアウトや内容は将来変更される可能性があるため、不透明な文字列としてのみ解釈してください。他のクライアント プロパティ API と同様に、`sessionId` の変更に対するコールバックを登録するために `XGameStreamingRegisterClientPropertiesChanged` を使用することをお勧めします。

## Example

```C++ theme={null}
// Register for client properties changed notifications 
void GameStreamingClientManager::OnClientConnected(XGameStreamingClientId client)
{
    XGameStreamingClientPropertiesChangedRegistrationToken token = {0};
    XGameStreamingRegisterClientPropertiesChanged(
            client, m_taskQueue, this, &OnClientPropertiesChanged, &token);
}

void GameStreamingClientManager::OnClientPropertiesChanged(
    void* context,
    XGameStreamingClientId client,
    uint32_t updatedPropertiesCount,
    XGameStreamingClientProperty* updatedProperties)
{
    for (uint32_t i = 0; i < updatedPropertiesCount; ++i)
    {
        switch (updatedProperties[i])
        {
        case XGameStreamingClientProperty::SessionId:
        {
            // allocate memory for sessionId
            char sessionId[SessionIdMaxBytes];

            // get session id of the client
            size_t bytesUsed = 0;
            HRESULT hr = XGameStreamingGetSessionId(client, _countof(sessionId), sessionId, &bytesUsed);

            if (SUCCEEDED(hr)) {
                // Game logic to use session id
            }
            else if (hr == E_GAMESTREAMING_NO_DATA) {
                // Game logic to handle no data for client
            }
            else
            {
                // Default error case
                LogFormat(L"XGameStreamingGetSessionId failed %x", hr);
            }

            break;
        }

        default:
            // A characteristic we are not tracking - do nothing
            break;
        }
    }
}

```

## Requirements

**ヘッダー:** xgamestreaming.h\
**ライブラリ:** xgameruntime.lib\
**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## See also

[XGameStreaming](/reference/system/xgamestreaming/xgamestreaming_members)
[XGameStreamingRegisterClientPropertiesChanged](/reference/system/xgamestreaming/functions/xgamestreamingregisterclientpropertieschanged)


## Related topics

- [XGameStreamingClientProperty](/ja-jp/reference/system/xgamestreaming/enums/xgamestreamingclientproperty.md)
- [XGameStreaming](/ja-jp/reference/system/xgamestreaming/xgamestreaming_members.md)
- [GDK 向け Unity C# API ラッパー](/ja-jp/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XGameStreamingGetClients](/ja-jp/reference/system/xgamestreaming/functions/xgamestreaminggetclients.md)
- [XGameStreamingGetConnectionState](/ja-jp/reference/system/xgamestreaming/functions/xgamestreaminggetconnectionstate.md)
