Microsoft DirectX 8.0 (C++)

Using Callback Functions

A callback function is essentially an event handler that is implemented by an application and called by the system. Microsoft® Windows® applications typically implement multiple callback functions, each one designed for a particular set of events. When an event occurs, the system notifies the application by calling the appropriate callback function. The callback function also usually has a parameter list that the system can use to pass the application more detailed information about the event. The most common example of a callback function is the window procedure. This function is used by the system to pass Windows messages to the applications that owns the window.

Microsoft DirectX® uses callback functions for a variety of purposes. For example, your system supports multiple devices. Microsoft DirectInput® represents each device by a device object, that contains the details of the device's capabilities. Your application will typically need to enumerate the available devices and to examine the device objects in order to handle user input properly. To do this enumeration, you must implement a DIEnumDeviceObjectsCallback callback function.

You start the enumeration process by calling IDirectInputDevice8::EnumObjects and passing the method a pointer to your DIEnumDeviceObjectsCallback callback function. The system will call this function once for each device, and it will pass in a DIDEVICEOBJECTINSTANCE structure containing information about the device's capabilities. After your callback function has processed the information, it can return DIENUM_CONTINUE to request the next device object, or DIENUM_STOP to stop the enumeration.

For more information, see Implementing a Callback Function.

DirectX uses a number of other callback functions for a variety of purposes. For details, see the documentation for the particular DirectX component.