Platform SDK: DirectX |
The information in this topic pertains only to applications written in C++. See DirectInput Visual Basic Tutorials.
After creating the DirectInput system, call the IDirectInput7::EnumDevices method to enumerate the joysticks. The following code accomplishes this.
// pdi is an initialized pointer to IDirectInput7 pdi->lpVtbl->EnumDevices(pdi, DIDEVTYPE_JOYSTICK, InitJoystickInput, pdi, DIEDFL_ATTACHEDONLY);
The method call is in the C form. Note that you could use the IDirectInput7_EnumDevices macro to simplify the call. All DirectInput methods have corresponding macros defined in Dinput.h that expand to the appropriate C or C++ syntax.
The DIDEVTYPE_JOYSTICK constant, passed as the second parameter, specifies the type of device to be enumerated.
InitJoystickInput is the address of a callback function to be called each time a joystick is found. This is where the individual devices will be initialized in the following steps of the tutorial.
The fourth parameter can be any 32-bit value that you want to make available to the callback function. In this case it's a pointer to the DirectInput interface, which the callback function needs to know so it can call the IDirectInput7::CreateDeviceEx method.
The last parameter, DIEDFL_ATTACHEDONLY, is a flag that restricts enumeration to devices that are attached to the computer.