Platform SDK: DirectX

Loading Effects from a File

[Visual Basic]

This topic pertains only to applications developed in C++. DirectX for Visual Basic does not support effect files.

[C++]

Using the Force Editor supplied with the DirectX 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 IDirectInputDevice7::EnumEffectsInFile method. By default, the enumeration is limited to the standard 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_lpdid7 is a valid IDirectInputDevice7 pointer to a 
// force feedback device. 

// The array of effect pointers is declared globally. 
LPDIRECTINPUTEFFECT pEff[3];
.
.
.
g_lpdid7->EnumEffectsInFile("FEdit1.ffe", EnumEffectsInFileProc,
        NULL, DIFEF_MODIFYIFNEEDED);
.
.
.

The following callback procedure is called once for each effect in the file or until it returns DIENUM_STOP.

BOOL CALLBACK EnumEffectsInFileProc(LPCDIFILEEFFECT lpdife, 
        LPVOID pvRef)
 
    {
    HRESULT     hr;
    static int  i;
 
// Because the DIFEF_MODIFYIFNEEDED flag was passed, the 
// effect parameters might be modified in lpdife->lpDiEffect.

    hr = g_lpdid7->CreateEffect(lpdife->GuidEffect, 
            lpdife->lpDiEffect,
            &pEff[i], NULL);
    if (FAILED(hr))
        {
        // Error handling
        }
    if (++i > 2) return DIENUM_STOP;
    else return DIENUM_CONTINUE;
    }