Skip to main content
GameDev.net gamedev.net
🔒 Locked

A quick Direct Input question

Started by Cyphoid Feb 2, 2006 at 5:45 PM 3 replies 850+ views
Original Post
Cyphoid
Cyphoid
I have a quick question: I am attempting to initialize a Direct Input device in DX 9.0. The input device pointer is located inside a class as follows: class DXInput { public: HRESULT InitializeDirectInputDevice(HINSTANCE hInstance); ... ... private: LPDIRECTINPUT8 pDInputObject; ... ... }; Inside the InitializeDirectInputDevice method is the following: { ... ... hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&pDInputObject, NULL); if (FAILED(hr)) return E_FAIL; ... ... return S_OK; } Yet this does not work. It works when the LPDIRECTINPUT8 object IS NOT a member of the class, but not when it IS a member. Could somebody please tell me what I am doing wrong, or if it is a legitimate way to do it at all?
jollyjeffers
jollyjeffers
This could be some odd COM-related quirk, but even that wouldn't make much sense [smile]

What exactly is the error? I presume the returned HRESULT triggers the FAILED() conditional? What is the value of hr after DirectInput8Create()?

Also, try cranking up the DirectInput debug output - see if it tells you anything useful.

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Cyphoid
Cyphoid
Sorry, I should have thought of that...

hr becomes -2147467261 or 0x80004003 (both are the same number).

I think that when I checked, it rings up as an "Invalid pointer".
Cyphoid
Cyphoid
I hate to do this, but ~bump~.

I would really like to know why this is happening.
don
don
This works fine on my machine...


#define INITGUID#define DIRECTINPUT_VERSION 0x0800#include <windows.h>#include <dinput.h>#pragma comment(lib, "dinput8.lib")class DXInput{public:    HRESULT InitializeDirectInputDevice (HINSTANCE hInst);    DXInput()    {        pDInputObject = NULL;    }    ~DXInput()    {        if (pDInputObject)            pDInputObject->Release();    }    private:    LPDIRECTINPUT8 pDInputObject;};HRESULT DXInput::InitializeDirectInputDevice (    HINSTANCE hInstance    ){    HRESULT hr;        hr = DirectInput8Create(        hInstance,        DIRECTINPUT_VERSION,        IID_IDirectInput8,        (void**)&pDInputObject,        NULL        );            return hr;}INT WINAPIWinMain (    HINSTANCE hInstance,    HINSTANCE hPrevInstance,    LPSTR lpCmdLine,    int nShowCmd     ){HRESULT hr;DXInput * pDI;    pDI = new DXInput();    if (!pDI)        DebugBreak();            hr = pDI->InitializeDirectInputDevice(hInstance);    if (FAILED(hr))        DebugBreak();    delete pDI    ;        return 0;}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.