DirectInput8Create fails : E_INVALIDARG

2.1k views Asked by At

I'm using DirectInput with Direct3D 11, and compiling for x64 and I get an E_INVALIDARG from this line:

HRESULT hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, reinterpret_cast<void **>(&this->_d8Input), 0);

When I set a break point to look at what is going on I get no sign of any invalid arguments. My hInstance is valid, so is the _d8Input pointer and the DIRECTINPUT_VERSION is set to 0x0800.

I've used direct input with D3D9 before, in the exact same way and didn't have any problems. What am I missing ?

Thanks.

2

There are 2 answers

0
dotminic On BEST ANSWER

Ok, it turns out I was compiling with /SUBSYSTEM:CONSOLE and the hInstance passed in from WinMain when using a console subsystem doesn't please DirectInput8Create at all.

2
Anya Shenanigans On

Ok, having just downloaded the latest DirectX SDK and Platform SDK, so I could test this in 64bit, I created an insanely simple 64bit application. For the stdafx.h file I added:

#define DIRECTINPUT_VERSION 0x0800
#include <Dinput.h>

and in the _tWinMain function I added:

void *outPtr = NULL;
HRESULT aResult = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, &outPtr, NULL);

if (aResult != DI_OK) {
    LPCWSTR emesg = L"??";
    switch (aResult) {
    case DIERR_BETADIRECTINPUTVERSION: emesg = L"Beta Directinput version"; break;
    case DIERR_INVALIDPARAM: emesg = L"Invalid Parameter"; break;
    case DIERR_OLDDIRECTINPUTVERSION: emesg = L"Old Directinput Version"; break;
    case DIERR_OUTOFMEMORY: emesg = L"Out of Memory"; break;
    }
    MessageBox(GetDesktopWindow(), emesg, emesg, 0);
}

for linker options, I added dinput8.lib and dxguid.lib

Compiled, checked that the application was 64bit, and it executes cleanly without generating an invalid parameter message. I get a valid value in the outPtr variable. I even looked at the content of the dinput.h file, which seems to indicate that DIRECTINPUT_VERSION is set to 0x0800 be default.

I'm at a loss, this 'just should work' in both 32bit and 64bit.

I get an invalid pointer error when I use a NULL value instead of outPtr, so that seems to indicate that the issue isn't an invalid value from the pointer.

I do get an invalid parameter when I use anything other than a valid hInstance - when I replaced the value with 0, I got the same error you saw. Perhaps the hInstance value is not initialized correctly?