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

# XStoreCreateContext

> XStoreCreateContext

# XStoreCreateContext

지정된 사용자에 대한 스토어 컨텍스트를 만듭니다.

## 구문

```cpp theme={null}
HRESULT XStoreCreateContext(  
         const XUserHandle user,  
         XStoreContextHandle* storeContextHandle  
)  
```

### 매개 변수

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

스토어 컨텍스트를 만들 사용자입니다.\
이 매개 변수는 PC 게임에만 선택 사항입니다. 단순히 nullptr 값을 전달하세요. PC에서는 Microsoft Store에 로그인한 사용자가 자동으로 사용되며 이 매개 변수는 무시됩니다.
콘솔 게임에는 유효한 XUser가 필요합니다.

*storeContextHandle*   \_Out\_\
형식: XStoreContextHandle\*

성공 시 만들어진 스토어 컨텍스트를 포함합니다.

### 반환 값

형식: HRESULT

HRESULT 성공 또는 오류 코드입니다.

## 설명

**참고:** 콘솔에서 이 함수에 의해 만들어진 XStoreContextHandle은 일시 중단 또는 빠른 다시 시작 이벤트 후에 무효화됩니다. 이러한 조건을 안전하게 처리하려면 게임이 일시 중단된 상태에서 다시 시작될 때마다 XStoreContextHandle을 닫고 다시 만드는 것이 좋습니다.

<Note>이 함수는 시간에 민감한 스레드에서 호출하기에 안전하지 않습니다. 자세한 내용은 [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)를 참조하세요.</Note>

이 함수가 만든 **XStoreContextHandle** 사용을 완료하면 [XStoreCloseContextHandle](/reference/system/xstore/functions/xstoreclosecontexthandle)을 사용하여 닫아야 합니다. 핸들을 닫지 않으면 메모리 누수가 발생합니다. 스토어 컨텍스트는 여러 **XStore** API 호출에서 정보를 검색할 사용자를 식별하는 데 사용됩니다. 다음 코드 조각은 스토어 컨텍스트를 만드는 예를 보여 줍니다.

```cpp theme={null}
void CALLBACK GameLicenseChangedCallback(void* context)
{
    UNREFERENCED_PARAMETER(context);
    printf("**** License Changed ****\r\n");
}

void CreateStoreContextHandle(XUserHandle userHandle, XTaskQueueHandle taskQueueHandle)
{
    // As a rule, it would be a good idea to create one of these
    // and keep it alive through the lifetime of the game
    XStoreContextHandle storeContextHandle;

    HRESULT hr = XStoreCreateContext(userHandle, &storeContextHandle);
    if (FAILED(hr))
    {
        printf("Failed creating store context: 0x%x\r\n", hr);
        return;
    }

    XTaskQueueRegistrationToken gameLicenseChangedToken = { 0 };
    hr = XStoreRegisterGameLicenseChanged(
        storeContextHandle,
        taskQueueHandle,
        storeContextHandle,
        GameLicenseChangedCallback,
        &gameLicenseChangedToken);

    if (FAILED(hr))
    {
        printf("Failed register for game license changed callback: 0x%x\r\n", hr);
        XStoreCloseContextHandle(storeContextHandle);
        return;
    }

    //Unregistering the license changed event and closing the XStoreContextHandle would usually go in the cleanup/shutdown sections of your game code. 
    XStoreUnregisterGameLicenseChanged(
        storeContextHandle,
        gameLicenseChangedToken,
        true);

    XStoreCloseContextHandle(storeContextHandle);
}

```

## 요구 사항

**헤더:** XStore.h(XGameRuntime.h에 포함됨)

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

**지원 플랫폼:** Windows, XBOX One 제품군 콘솔 및 XBOX Series 콘솔

## 개념 설명서

* [Time-sensitive threads](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)
* [Basic store operations](https://learn.microsoft.com/gaming/gdk/docs/store/commerce/fundamentals/xstore-basic-store-operations)

## 참고 항목

[XStore](/reference/system/xstore/xstore_members)\
[XStoreCloseContextHandle](/reference/system/xstore/functions/xstoreclosecontexthandle)\
[XStoreRegisterGameLicenseChanged](/reference/system/xstore/functions/xstoreregistergamelicensechanged)


## Related topics

- [XStoreCloseContextHandle](/ko/reference/system/xstore/functions/xstoreclosecontexthandle.md)
- [XStoreQueryGameLicenseAsync](/ko/reference/system/xstore/functions/xstorequerygamelicenseasync.md)
- [XStoreQueryConsumableBalanceRemainingAsync](/ko/reference/system/xstore/functions/xstorequeryconsumablebalanceremainingasync.md)
- [XStoreUnregisterGameLicenseChanged](/ko/reference/system/xstore/functions/xstoreunregistergamelicensechanged.md)
- [XStoreCanAcquireLicenseForStoreIdAsync](/ko/reference/system/xstore/functions/xstorecanacquirelicenseforstoreidasync.md)
