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

# XblSocialAddFriendRequestCountChangedHandler

> Registers an event handler for notifications of changes to the number of incoming friend requests for the registering user.

# XblSocialAddFriendRequestCountChangedHandler

Registers an event handler for notifications of incoming friend requests for the registering user.

## Syntax

```cpp theme={null}
HRESULT XblSocialAddFriendRequestCountChangedHandler(  
         XblContextHandle xboxLiveContext,  
         XblSocialIncomingFriendRequestCountChangedHandler handler,  
         void* handlerContext,  
         XblFunctionContext* handlerFunctionContext  
)  
```

### Parameters

*xboxLiveContext*   \_In\_\
Type: [XblContextHandle](https://docs.xbox.com/reference/live/xsapi-c/types_c/handles/xblcontexthandle.md)

An XBOX services context handle created with [XblContextCreateHandle](https://docs.xbox.com/reference/live/xsapi-c/xbox_live_context_c/functions/xblcontextcreatehandle.md). The handler receives notifications for the user associated with this context.

*handler*   \_In\_\
Type: [XblSocialIncomingFriendRequestCountChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialincomingfriendrequestcountchangedhandler.md)

The callback function that receives notifications.

*handlerContext*   \_In\_opt\_\
Type: void\*

Client context pointer to be passed back to the handler.

*handlerFunctionContext*   \_Out\_\
Type: XblFunctionContext\*

Passes back a token that identifies the handler. Pass this token to [XblSocialRemoveFriendRequestCountChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialremovefriendrequestcountchangedhandler.md) to remove the handler.

### Return value

Type: HRESULT

Returns `S_OK` if the handler was registered. Returns `E_INVALIDARG` if *xboxLiveContext*, *handler*, or *handlerFunctionContext* is null.

## Remarks

The handler receives notifications when the number of pending incoming friend requests for the user changes. Each notification passes an [XblSocialFriendRequestCountChangedEventArgs](https://docs.xbox.com/reference/live/xsapi-c/social_c/structs/xblsocialfriendrequestcountchangedeventargs.md) structure that contains the current count.

You don't need to subscribe to these notifications separately. When you register a handler, the XBOX Services API (XSAPI) creates a Real-Time Activity (RTA) subscription to social relationship notifications for the context's user, or reuses the existing one. Friend request count handlers and [social relationship changed handlers](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialaddsocialrelationshipchangedhandler.md) share this subscription. XSAPI removes the subscription only after you remove all handlers of both types for the context.

If the handler throws a C++ exception, XSAPI catches and logs it.

Call [XblSocialRemoveFriendRequestCountChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialremovefriendrequestcountchangedhandler.md) to unregister the event handler.

## Requirements

**Header:** social\_c.h

**Library:** Microsoft.Xbox.Services.142.C.lib or Microsoft.Xbox.Services.143.C.lib

## See also

[social\_c](https://docs.xbox.com/reference/live/xsapi-c/social_c/social_c_members.md)\
[XblSocialIncomingFriendRequestCountChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialincomingfriendrequestcountchangedhandler.md)\
[XblSocialRemoveFriendRequestCountChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialremovefriendrequestcountchangedhandler.md)\
[XblSocialAddSocialRelationshipChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialaddsocialrelationshipchangedhandler.md)


## Related topics

- [XblSocialIncomingFriendRequestCountChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialincomingfriendrequestcountchangedhandler.md)
- [XblSocialRemoveFriendRequestCountChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialremovefriendrequestcountchangedhandler.md)
- [XblSocialAddSocialRelationshipChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialaddsocialrelationshipchangedhandler.md)
- [Handling a social relationship change](https://docs.xbox.com/services/xbox-services/community/people-system/how-to/live-handling-a-relationship-change.md)
- [XblSocialRelationshipChangedHandler](https://docs.xbox.com/reference/live/xsapi-c/social_c/functions/xblsocialrelationshipchangedhandler.md)
