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

# XUserCloseHandle

> XUserCloseHandle

# XUserCloseHandle

특정 사용자 핸들을 닫습니다.

## 구문

```cpp theme={null}
void XUserCloseHandle(  
         XUserHandle user  
)  
```

### 매개변수

*user*   \_In\_\
형식: XUserHandle

닫을 사용자 핸들입니다.

### 반환값

형식: void

## 설명

**XUser** API에서 가져오는 각 **XUserHandle**에 대해 XUserCloseHandle 함수를 한 번만 호출해야 합니다.
XUserCloseHandle 함수를 호출하여 사용자를 나타내는 모든 핸들을 닫을 수도 있습니다.

다음 예제는 게임 세션에 사용자를 비동기적으로 추가하는 방법을 보여줍니다.

```cpp theme={null}
HRESULT AddUserComplete(XAsyncBlock* ab)
{
    unique_user_handle user;
    RETURN_IF_FAILED(XUserAddResult(ab, &user));

    XUserLocalId userLocalId;
    XUserGetLocalId(user.get(), &userLocalId);

    auto iter = std::find_if(
        _users.begin(),
        _users.end(),
        [&userLocalId](const User& candidate)
    {
        XUserLocalId candidateUserLocalId;
        XUserGetLocalId(candidate.Handle(), &candidateUserLocalId);
        return candidateUserLocalId == userLocalId;
    });

    // User already known
    if (iter != _users.end())
    {
        appLog.AddLog("User already in list\n");
        return S_OK;
    }

    try
    {
        _users.emplace_back(user.get());
        _users.back().LoadGamerPicAsync(_queue);
    }
    CATCH_RETURN();

    return S_OK;
}

HRESULT AddUser(bool allowGuests, bool silent)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = _queue;
    asyncBlock->context = this;
    asyncBlock->callback = [](XAsyncBlock* ab)
    {
        auto asyncBlock = std::unique_ptr<XAsyncBlock>(ab);
        LOG_IF_FAILED(static_cast<UserWindow*>(ab->context)->AddUserComplete(ab));
    };

    XUserAddOptions options = XUserAddOptions::None;

    if (allowGuests)
    {
        WI_SET_FLAG(options, XUserAddOptions::AllowGuests);
    }

    if (silent)
    {
        WI_SET_FLAG(options, XUserAddOptions::AddDefaultUserSilently);
    }

    if (SUCCEEDED_LOG(XUserAddAsync(
        options,
        asyncBlock.get())))
    {
        // The call succeeded, so release the std::unique_ptr ownership of XAsyncBlock* since the callback will take over ownership.
        // If the call fails, the std::unique_ptr will keep ownership and delete the XAsyncBlock*
        asyncBlock.release();
    }

    return S_OK;
}
```

## 요구 사항

**헤더:** XUser.h

**라이브러리:** xgameruntime.lib

**지원되는 플랫폼:** Windows, Steam Deck, XBOX One 계열 콘솔 및 XBOX Series 콘솔

## 개념 문서

* [시간에 민감한 스레드](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 함께 보기

[XUser](/reference/system/xuser/xuser_members)

[XUserCloseSignOutDeferralHandle](/reference/system/xuser/functions/xuserclosesignoutdeferralhandle)

[XUserCompare](/reference/system/xuser/functions/xusercompare)


## Related topics

- [XUserDuplicateHandle](/ko/reference/system/xuser/functions/xuserduplicatehandle.md)
- [XUserCompare](/ko/reference/system/xuser/functions/xusercompare.md)
- [XUserAddAsync](/ko/reference/system/xuser/functions/xuseraddasync.md)
- [XUserAddByIdWithUiAsync](/ko/reference/system/xuser/functions/xuseraddbyidwithuiasync.md)
- [XUserAddByIdWithUiResult](/ko/reference/system/xuser/functions/xuseraddbyidwithuiresult.md)
