DirectX SDK

Step 2: Set Device Properties

[C++]

This topic pertains only to application development in Visual Basic. See DirectInput C/C++ Tutorials.

[Visual Basic]

Presuming you have found a suitable force-feedback device, the DirectInputDevice object created in the last step in order to check capabilities can be left in place. It requires some further initialization, as covered in Tutorial 3: Using the Joystick: setting the data format and cooperative level, and setting the range properties for input. Note that the cooperative level must include DISCL_EXCLUSIVE. Although you probably won't need background access to the device, the DISCL_BACKGROUND flag makes debugging easier, because you won't keep losing acquisition when you switch to the code window.

Call didev.SetCommonDataFormat(DIFORMAT_JOYSTICK2)
Call didev.SetCooperativeLevel(Me.hWnd, _
        DISCL_BACKGROUND Or DISCL_EXCLUSIVE)
' Set range properties...
.
.
.

For force feedback, you might also want to disable the autocenter property of the device, so that the default spring action will not interfere with effects you create:

Dim prop As DIPROPLONG
prop.lData = 0
prop.lHow = DIPH_DEVICE
prop.lObj = 0
prop.lSize = Len(prop)
Call didev.SetProperty("DIPROP_AUTOCENTER", prop)
 
didev.Acquire

Next: Step 3: Create an Effect