Microsoft DirectX 9.0

Step 1: Creating the DirectInput Mouse Device

After creating the Microsoft?DirectInput?object, your application should retrieve a pointer to an IDirectInputDevice8 interface, which is used to perform most mouse-related tasks. To do this, call the IDirectInput8::CreateDevice method.

The first parameter of IDirectInput8::CreateDevice is the globally unique identifier (GUID) for the device your application is creating. In this case, because the system mouse is used, your application should pass the predefined global variable GUID_SysMouse.

The second parameter is the address of a variable that is initialized with a valid IDirectInputDevice8 interface pointer if the call succeeds.

The third parameter specifies the address of the controlling object's IUnknown for use in COM aggregation. Because most applications do not use aggregation, the value of this parameter is usually NULL.

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

HRESULT             hr; 
hr = g_pDI->CreateDevice(GUID_SysMouse, &g_pMouse, NULL);

if (FAILED(hr)) {
	return FALSE;

After creating the DirectInput mouse device, go to Step 2: Setting the Mouse Data Format.

© 2002 Microsoft Corporation. All rights reserved.