Microsoft DirectX 9.0

IDirectInput8::CreateDevice Method

Creates and initializes an instance of a device based on a given globally unique identifier (GUID), and obtains an IDirectInputDevice8 interface.


HRESULT CreateDevice(      

    REFGUID rguid,     LPDIRECTINPUTDEVICE *lplpDirectInputDevice,     LPUNKNOWN pUnkOuter );


Reference to (C++) or address of (C) the instance GUID for the desired input device (see Remarks). The GUID is retrieved through the IDirectInput8::EnumDevices method, or it can be one of the predefined GUIDs listed below. For the following 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.
The default system keyboard.
The default system mouse.
Address of a variable to receive the IDirectInputDevice8 interface pointer if successful.
Address of the controlling object's IUnknown interface for Component Object Model (COM) aggregation, or NULL if the interface is not aggregated. Most callers pass NULL.

Return Value

If the method succeeds, the return value is DI_OK.

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

DIERR_DEVICENOTREGThe device or device instance is not registered with Microsoft?DirectInput? This value is equal to the REGDB_E_CLASSNOTREG standard COM return value.
DIERR_INVALIDPARAMAn invalid parameter was passed to the returning function, or the object was not in a state that permitted the function to be called. This value is equal to the E_INVALIDARG standard COM return value.
DIERR_NOINTERFACEThe specified interface is not supported by the object. This value is equal to the E_NOINTERFACE standard COM return value.
DIERR_NOTINITIALIZEDThe object has not been initialized.
DIERR_OUTOFMEMORYThe DirectInput subsystem couldn't allocate sufficient memory to complete the call. This value is equal to the E_OUTOFMEMORY standard COM return value.


Calling this method with pUnkOuter = NULL is equivalent to creating the object by CoCreateInstance (&CLSID_DirectInputDevice, NULL, CLSCTX_INPROC_SERVER, riid, lplpDirectInputDevice) and then initializing it with Initialize.

Calling this method with pUnkOuter != NULL is equivalent to creating the object by CoCreateInstance (&CLSID_DirectInputDevice, punkOuter, CLSCTX_INPROC_SERVER, &IID_IUnknown, lplpDirectInputDevice). The aggregated object must be initialized manually.

© 2002 Microsoft Corporation. All rights reserved.