Loading Effects from a File
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. LPDIRECTINPUTEFFECT pEff[3]; . . . g_lpdid->EnumEffectsInFile("FEdit1.ffe", EnumEffectsInFileProc, NULL, DIFEF_MODIFYIFNEEDED); . . .
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.
BOOL CALLBACK EnumEffectsInFileProc(LPCDIFILEEFFECT lpdife, LPVOID pvRef) { HRESULT hr; static int i; hr = g_lpdid->CreateEffect(lpdife->GuidEffect, lpdife->lpDiEffect, &pEff[i], NULL); if (FAILED(hr)) { // Error handling } if (++i > 2) return DIENUM_STOP; else return DIENUM_CONTINUE; }