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

# RegisterLampArrayCallback function reference

> Registers a LampArrayCallback that fires when a LampArray peripheral is connected or disconnected, returning a token for later unregistration.

# RegisterLampArrayCallback

Registers a callback function to be invoked each time a LampArray is connected or disconnected from the system.

## Syntax

```cpp theme={null}
HRESULT RegisterLampArrayCallback(
    LampArrayCallback lampArrayCallback,
    void* context,
    LampArrayCallbackToken* callbackToken);
```

### Parameters

*lampArrayCallback*   \_In\_
Type: [LampArrayCallback](/reference/lighting/lamparray/functions/lamparraycallback)

A caller-defined function to register. It will be invoked when LampArrays are connected or disconnected from the system.

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

A pointer to an object containing relevant information for the callback function. Typically, this is the calling object.

*callbackToken*   \_Out\_ \_Result\_zeroonfailure\_
Type: LampArrayCallbackToken\*

A token value that can be used to unregister the callback function at a later time.

### Return value

Type: HRESULT

Function result.

## Remarks

If any LampArray devices are attached at the time a callback is registered, the RegisterLampArrayCallback function will block until that callback is invoked for each attached device (meaning the callback will be invoked on the calling thread).

When the first callback is registered, the LampArray API starts a worker thread to handle ILampArray device attach and removal notifications. These events are infrequent, and the worker thread otherwise remains in a wait state. After the registration call returns, all subsequent LampArrayCallbacks will be invoked sequentially on this worker thread.

The following code is an example of registering and unregistering a LampArray callback:

```cpp theme={null}
void MyLampArrayCallback(
    _In_opt_ void* context,
    bool isAttached,
    _In_ ILampArray* lampArray)
{
    if (isAttached)
    {
        // Application-specific code to handle LampArray connection
    }
    else
    {
        // Application-specific code to handle LampArray disconnection
    }
}

void MonitorLampArrays(
    _In_ volatile bool & cancelMonitoring) noexcept
{
    LampArrayCallbackToken token = LAMPARRAY_INVALID_CALLBACK_TOKEN_VALUE;
    if (SUCCEEDED(RegisterLampArrayCallback(
        MyLampArrayCallback,
        nullptr /* context */,
        &token)))
    {
        while (!cancelMonitoring)
        {
            Sleep(100);
        }

        UnregisterLampArrayCallback(token, 5000);
    }
}
```

## Requirements

**Header:** LampArray.h

**Library:** xgameplatform.lib

**Supported platforms:** XBOX One family consoles and XBOX Series consoles

## See also

[Lighting API Overview](/build/core-features/common/lighting/gc-lighting-toc)\
[Lighting Basics](/build/core-features/common/lighting/lighting-basics)\
[LampArrayCallback](/reference/lighting/lamparray/functions/lamparraycallback)\
[UnregisterLampArrayCallback](/reference/lighting/lamparray/functions/unregisterlamparraycallback)


## Related topics

- [LampArrayCallback function reference](/reference/lighting/lamparray/functions/lamparraycallback.md)
- [UnregisterLampArrayCallback function reference](/reference/lighting/lamparray/functions/unregisterlamparraycallback.md)
- [RegisterLampArrayStatusCallback function](/reference/lighting/lamparray/functions/registerlamparraystatuscallback.md)
- [LampArrayStatusCallback function reference](/reference/lighting/lamparray/functions/lamparraystatuscallback.md)
- [LampArray API members reference](/reference/lighting/lamparray/lamparray_members.md)
