Microsoft DirectX 9.0

Programming Tips and Tools

This topic covers the following specialized programming tips.

Designing for Previous Versions of DirectInput

In the DirectInput8Create, IDirectInput8::Initialize, IDirectInputDevice8::Initialize, and IDirectInputEffect::Initialize methods, you are required to pass the Microsoft?DirectInput?version number. This parameter specifies which version of Microsoft DirectX?the DirectInput subsystem should emulate.

Applications designed for the latest version of DirectInput should pass the value DIRECTINPUT_VERSION as defined in Dinput.h.

Applications designed to run under previous versions should pass a value corresponding to the version of DirectInput for which they were designed, with the main version number in the high-order byte. For example, an application designed to run on DirectInput 3.0 should pass a value of 0x0300.

If you define DIRECTINPUT_VERSION as 0x0300 before including the Dinput.h header file, the header file generates structure definitions compatible with DirectInput 3.0.

If you do not define DIRECTINPUT_VERSION before including the Dinput.h header file, the header file generates structure definitions compatible with the current version of DirectInput. However, the DirectX 3–compatible structures are available under the same names with "_DX3" appended. For example, the DirectX 3–compatible DIDEVCAPS structure is called DIDEVCAPS_DX3.

You must also use the appropriate versions of the DirectInput and DirectInputDevice interfaces. For versions of DirectX prior to DirectX 7.0, you must use IDirectInput and either IDirectInputDevice or IDirectInputDevice2 (the latter is available for DirectX 5.0 or later.)

Preventing Response Delays During Debugging

When using the keyboard or mouse with DirectInput under Microsoft Windows?2000, you might notice short delays in response when you step through code during a debugging session. This behavior occurs only in debug mode, so it is not seen by your application's end users. However, this behavior can be eliminated in debug mode as well by adding the emulation value to the following registry key.

EmulationDWORD0x08 (for the keyboard)

0x10 (for the mouse)

0x18 (for both)

You can also switch to use emulation from the DirectX control panel by following these steps.

  1. Open the Windows control panel
  2. Open the DirectX control panel. Note that if you are using Windows XP, you might need to click Switch to Classic View to see the DirectX icon.
  3. Select the DirectInput tab.
  4. In the Debug Input Device Emulation section, you can check the Emulate Keyboard and Emulate Mouse boxes.

Without changing how DirectInput returns data, this value invokes an emulation mode that is not susceptible to those delays. These settings are global and affect all DirectInput clients. Performance only improves when using the debug binaries and only for applications that employ foreground exclusive device access. Some features, such as masking the Windows keys, are not available when devices are emulated so emulation is recommended only for debugging.

Note   If you are using earlier versions of DirectX, you must do a debug software development kit (SDK) install in order to get the correct debug dynamic-link library (DLL) onto your computer.

Avoiding Duplicate Registry Keys

For every application that uses DirectInput 8.0 or later versions, DirectInput creates a key in the following registry.


This allows the independent hardware vendors (IHVs) to turn off their own device mapping for certain applications. During debugging, however, each build will generate a new key which contains a time stamp and the file size. To avoid generating multiple keys in the registry, use the binary value, AppldFlag.

The following table lists the possible values for AppldFlag.

1The time stamp is ignored when generating the key.
2The file size is ignored when generating the key.
3Both the time stamp and file size are ignored when generating the key.

If AppldFlag is set to 3, all builds of applications with the same file name will use the same key.

Note  The AppldFlag value should only be set on test computers to avoid the possibility of two applications that ship with the same file name interfering with each other's input control mappings.

Force Editor

Force Editor has the following characteristics.


The Force Editor application enables you to design force-feedback effects and test them singly or in combination. Effects can be saved to file and then loaded into DirectInput applications.


Executable: (SDK root)\Bin\Dxutils\Fedit.exe

User's Guide

The Force Editor has its own documentation. When you've launched Fedit.exe, press F1 for online Help. The Help file can also be launched directly.

(SDK root)\Bin\Dxutils\Fedit.chm

GetDeviceData and an Unacquired Device

When using the debug version of Microsoft DirectPlay? you may notice some unusual behavior from the IDirectInputDevice8::GetDeviceData method when a device is unacquired. If you call IDirectInputDevice8::GetDeviceData and the device is not acquired, random bytes will be placed in the device data buffer and the value of the pdwInOut parameter will not be changed. Therefore, if your application does not check for the DPNERR_UNACQUIRED error code, your application will mistakenly determine that there is data in the buffer.

© 2002 Microsoft Corporation. All rights reserved.