Platform SDK: DirectX

Step 1: Create the DirectInput Mouse Device

[Visual Basic]

The information in this topic pertains only to applications written in C++. See DirectInput Visual Basic Tutorials.

[C++]

After creating the DirectInput object, your application should retrieve a pointer to an IDirectInputDevice7 interface, which will be used to perform most mouse-related tasks. To do this, call the IDirectInput7::CreateDeviceEx method.

The first parameter of CreateDeviceEx is the globally unique identifier (GUID) for the device your application is creating. In this case, since the system mouse will be used, your application should pass the predefined global variable GUID_SysMouse.

The second parameter is the GUID of the desired DirectInputDevice interface. Most applications will want the latest interface and so will pass IID_IDirectInputDevice7.

The third parameter is the address of a variable that will be initialized with a valid IDirectInputDevice7 interface pointer if the call succeeds.

The fourth parameter specifies the address of the controlling object's IUnknown interface for use in COM aggregation. Your application probably won't be using aggregation, in which case the parameter will be NULL.

The following sample code attempts to retrieve a pointer to an IDirectInputDevice7 interface. If the call fails, FALSE is returned. It is assumed that g_pdi is a valid pointer to IDirectInput7.

LPDIRECTINPUTDEVICE g_pMouse; 
HRESULT             hr; 
 
hr = g_pdi->CreateDeviceEx(GUID_SysMouse, IID_IDirectInputDevice7,
        (void**)&g_pMouse, NULL);
 
if (FAILED(hr)) {
    return FALSE;
}

Next: Step 2: Set the Mouse Data Format