Microsoft DirectX 9.0

Loading Effects from a File

Using the Force Editor supplied with the Microsoft?DirectX® software development kit (SDK), or another application that uses the same file format, you can design effects and save them in a file. You can then use these effects in any application by loading them at run time.

To load effects, call the IDirectInputDevice8::EnumEffectsInFile method. By default, the enumeration is limited to the standard Microsoft DirectInput?effects, but you can enumerate other effects by setting the DIFEF_INCLUDENONSTANDARD flag. By setting the DIFEF_MODIFYIFNEEDED flag, you can also instruct DirectInput to modify the parameters of effects, if necessary, so that they work on the device. (For example, an effect authored for two axes can be made to work on a single-axis steering wheel.)

In the following code example, the first three standard effects are loaded from a file and created as DirectInputEffect objects.

// g_lpdid is a valid IDirectInputDevice8 pointer to a 
// force feedback device. 

// The array of effect pointers is declared globally. 

The following callback function is called once for each effect in the file or until it returns DIENUM_STOP. Note that because the DIFEF_MODIFYIFNEEDED flag was passed, the effect parameters may have been modified in lpdife->lpDiEffect. The callback creates the effect with these modified parameters.

        LPVOID pvRef)

    HRESULT     hr;
    static int  i;

    hr = g_lpdid->CreateEffect(lpdife->GuidEffect, 
    if (FAILED(hr))
        // Error handling
    if (++i > 2) return DIENUM_STOP;
    else return DIENUM_CONTINUE;

© 2002 Microsoft Corporation. All rights reserved.