DirectX SDK

IDirectInput7::CreateDeviceEx

The IDirectInput7::CreateDeviceEx method creates and initializes an instance of a device based on a given GUID, and obtains an IDirectInputDevice, IDirectInputDevice2, or IDirectInputDevice7 interface.

HRESULT CreateDeviceEx(
  REFGUID rguid,   
  REFIID riid,
  LPVOID *pvOut,  
  LPUNKNOWN pUnkOuter 
);

Parameters

rguid
Reference to (C++) or address of (C) the instance GUID for the desired input device (see Remarks). The GUID is retrieved through the IDirectInput7::EnumDevices method, or it can be one of the following predefined GUIDs:
GUID_SysKeyboard
The default system keyboard.
GUID_SysMouse
The default system mouse.

For the preceding GUID values to be valid, your application must define INITGUID before all other preprocessor directives at the beginning of the source file, or link to Dxguid.lib.

riid
Unique identifier for the desired interface. Currently accepted values are IID_IDirectInputDevice, IID_IDirectInputDevice2, and IID_IDirectInputDevice7.
pvOut
Address of a variable to receive the interface pointer if successful.
pUnkOuter
Address of the controlling object's IUnknown interface for COM aggregation, or NULL if the interface is not aggregated. Most callers pass NULL.

Return Values

If the method succeeds, the return value is DI_OK.

If the method fails, the return value can be one of the following:

DIERR_DEVICENOTREG
DIERR_INVALIDPARAM
DIERR_NOINTERFACE
DIERR_NOTINITIALIZED
DIERR_OUTOFMEMORY

Remarks

In C++ the rguid parameter must be passed by reference; in C, which does not permit passing by-reference, it must be passed by address. The following is an example of a C++ call:

lpdi->CreateDevice(GUID_SysKeyboard, &pdev, NULL);

The following shows the same call in C:

lpdi->lpVtbl->CreateDevice(lpdi, &GUID_SysKeyboard, &pdev, NULL);

Most applications will want to pass IID_IDirectInputDevice7 in the riid parameter to obtain the IDirectInputDevice7 interface.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in dinput.h.
  Import Library: Use dinput.lib.