Platform SDK: DirectX

Effect Enumeration

[C++]

The IDirectInputDevice7::EnumEffects method returns information about the support offered by the device for various kinds of effects.

It is important to distinguish between supported effects and created effects, or effect objects. A supported effect might be a constant force that can be shaped by an envelope. However, this effect has no properties such as magnitude, direction, duration, attack, or fade. You set these properties when you create an effect object in your application. A supported effect can be represented by many effect objects, each with different parameters—for example, several constant forces, each with different duration, magnitude, and direction.

For information on enumerating created effects, see Effect Object Enumeration.

Like other DirectInput enumerations, the IDirectInputDevice7::EnumEffects method requires a callback function; this is documented with the placeholder name DIEnumEffectsCallback, but you can use a different name if you want. This function is called for each effect enumerated. Within the function, you can obtain the GUID for each effect, get information about the extent of hardware support, and create one or more effect objects whose methods you can use to manipulate the effect.

The following code example calls the IDirectInputDevice7::EnumEffects method that sets the enumeration in motion. The pvRef parameter of the callback can be any 32-bit value; in this case, it is a pointer to the device interface, used for getting information about effects supported by the device and for creating effect objects.

HRESULT  hr;
// LPDIRECTINPUTDEVICE lpdid2;   // already initialized 
 
BOOL CALLBACK DIEnumEffectsCallback(LPCDIEFFECTINFO pdei, 
                                LPVOID pvRef)
{
    LPDIRECTINPUTDEVICE2 lpdid = pvRef;   // Pointer to calling device
    LPDIRECTINPUTEFFECT  lpdiEffect;      // Pointer to created effect
    DIEFFECT             diEffect;        // Params for created effect
    DICONSTANTFORCE      diConstantForce; // Type-specific parameters
                                          // for diEffect
    
 
    if (DIEF_GETTYPE(pdei->dwEffType) == DIEFFT_CONSTANTFORCE)
    {
       /* Here you can extract information about support for the 
          effect type (from pdei), and tailor your effects 
          accordingly. For example, the device might not support
          envelopes for this type of effect. */
       .
       .
       .
       // Create one or more constant force effects. 
       // For each, you have to initialize a DICONSTANTFORCE 
       // and a DIEFFECT structure. 
       // See detailed example at Creating an Effect.
       .
       .
       .
        hr = pdid->CreateEffect(pdei->guid,
                                &diEffect,
                                &lpdiEffect,
                                NULL);
       .
       .
       .
    }
    // And so on for other types of effect
   .
   .
   .
 
    return DIENUM_CONTINUE;
}  // End of callback
.
.
.
// Set the callback in motion.
hr = lpdid2->EnumEffects(&EnumEffectsCallback,
                        lpdid2, DIEFT_ALL);

For more information on how to initialize an effect, see Creating an Effect.

[Visual Basic]

The DirectInputDevice.GetEffectsEnum method enumerates effects supported by the device. It returns a DirectInputEnumEffects object representing the collection of supported effects. Methods of DirectInputEnumEffects can be used to get information about a particular effect.

It is important to distinguish between supported effects and created effects, or effect objects. A supported effect might be a constant force that can be shaped by an envelope. However, this effect has no properties such as magnitude, direction, duration, attack, or fade. You set these properties when you create an effect object in your application. A supported effect can be represented by many effect objects, each with different parameters—for example, several constant forces, each with different duration, magnitude, and direction.

The following code example shows how an application could enumerate hardware-specific effects, looking for a particular one supported by the Microsoft® SideWinder® joystick. If the desired effect is not found, the application substitutes one of the standard effects:

Const BasketballDribble = _
        "{E84CD1AC-81FA-11D0-94AB-0080C74C7E95}"
Dim diEnumEffects as DirectInputEnumEffects
Dim EffGuid As String
Dim i as Integer

' diDev is a DirectInputDevice object.
Set diEnumEffects = didev.GetEffectsEnum(DIEFT_HARDWARE)
For i = 1 To diEnumEffects.GetCount
  If diEnumEffects.GetEffectGuid(i) = BasketballDribble Then
    EffGuid = BasketballDribble
    Exit For
  End If
Next i
If EffGuid <> BasketballDribble Then
  EffGuid = "GUID_Sine"
  ' Set parameters for emulated dribble here
End If
 
' Ultimately pass EffGuid to DirectInputDevice.CreateEffect.