> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XUserGetGamertag

> XUserGetGamertag

Retrieves the gamertag for a specific user.

## Syntax

```cpp theme={null}
HRESULT XUserGetGamertag(  
         XUserHandle user,
         XUserGamertagComponent gamertagComponent,
         size_t gamertagSize,  
         char* gamertag,  
         size_t* gamertagUsed  
)  
```

### Parameters

*user*   \_In\_\
Type: XUserHandle

A handle to the user to retrieve the gamertag for.

*gamertagComponent*   \_In\_\
Type: [XUserGamertagComponent](https://docs.xbox.com/reference/system/xuser/enums/xusergamertagcomponent.md)

Type of gamertag to retrieve.

*gamertagSize*   \_In\_\
Type: size\_t

Size in bytes of the buffer in the *gamertag* parameter.

*gamertag*   \_Out\_writes\_bytes\_to\_(gamertagSize,*gamertagUsed)\
Type: char*

Contains the gamertag for a specific user.

*gamertagUsed*   \_Out\_opt\_\
Type: size\_t\*

Contains the amount of the buffer for holding the gamertag.

### Return value

Type: HRESULT

HRESULT success or error code.

| Return Code | Description |
| - | - |
| S\_OK | The operation succeeded. |
| E\_GAMEUSER\_RESOLVE\_USER\_ISSUE\_REQUIRED | The user must use a UI to resolve the issue. Call [XUserResolveIssueWithUiAsync](https://docs.xbox.com/reference/system/xuser/functions/xuserresolveissuewithuiasync.md) to display the UI to the user. |
| E\_INSUFFICIENT\_BUFFER | The size of the buffer indicated by *gamertagSize* is not large enough to hold the requested component. |
| E\_INVALIDARG | Invalid *gamertagComponent* provided. |

For a list of error codes, see [Error Codes](https://docs.xbox.com/reference/errorcodes.md).

## Remarks

To retrieve the user ID for a specific user, call [XUserGetId](https://docs.xbox.com/reference/system/xuser/functions/xusergetid.md).

To retrieve the state of a specific user, call [XUserGetState](https://docs.xbox.com/reference/system/xuser/functions/xusergetstate.md).

To retrieve the age group for a specific user, call [XUserGetAgeGroup](https://docs.xbox.com/reference/system/xuser/functions/xusergetagegroup.md).

## Requirements

**Header:** XUser.h

**Library:** xgameruntime.lib

**Supported platforms:** Windows, Steam Deck, XBOX One family consoles and XBOX Series consoles

## See also

[XUser](https://docs.xbox.com/reference/system/xuser/xuser_members.md)

[XUserGetId](https://docs.xbox.com/reference/system/xuser/functions/xusergetid.md)

[XUserGetState](https://docs.xbox.com/reference/system/xuser/functions/xusergetstate.md)

[XUserGetAgeGroup](https://docs.xbox.com/reference/system/xuser/functions/xusergetagegroup.md)


## Related topics

- [XUserGamertagComponent](https://docs.xbox.com/reference/system/xuser/enums/xusergamertagcomponent.md)
- [Gamertags overview](https://docs.xbox.com/services/xbox-services/fundamentals/identity/user-profile/gamertags/live-gamertags-overview.md)
- [Best practices and testing for modern gamertags](https://docs.xbox.com/services/xbox-services/fundamentals/identity/user-profile/gamertags/live-modern-gamertags-best-practices-and-testing.md)
- [Certification Tested XBOX Requirements for XBOX Games](https://docs.xbox.com/publishing/certification/console-cert-tested-requirements.md)
- [XBOX Requirements for XBOX Games](https://docs.xbox.com/publishing/certification/xbox-requirements.md)
