0

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.

dotminic
  • 1,135
  • 2
  • 14
  • 28
  • DIRECTINPUT_VERSION is set before you #include ? – Anya Shenanigans Mar 06 '11 at 22:40
  • @Peter Huene - The DirectX SDK includes a dinput8.lib for both 32 and 64 bit applications – Anya Shenanigans Mar 06 '11 at 22:43
  • Adding back my comment since I deleted it (because it was an inexperienced guess) without seeing that Petesh had replied. Paraphrasing original comment: "My guess is that there is no DX8 x64 implementation. The first x64 DX appears to be an update to 9.0 made in 2005". – Peter Huene Mar 06 '11 at 23:00
  • @Petesh, yep it's set before the include @Peter Huene, I'm using DX11 and DI8, and after some testing, it just fails, no difference if I'm using 32 or 64 bits. – dotminic Mar 07 '11 at 08:52

2 Answers2

1

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?

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • I'm at a loss too. I moved the DI init code to my WinMain function, did a very simple test, and it fails. I'm using the hInstance passed in from WinMain. I just have NO idea why. I've DI loads of times with DX9 and never had any problems. And it seems it's not even got anything to do with the DX version since even just in WinMain the creation fails. – dotminic Mar 07 '11 at 08:55
  • I hate to suggest it, but have you tried reinstalling the latest DirectX SDK, and trying again? This sounds like something is not installed properly. My simple attempt doesn't even have a CoInitialize and it succeeds (as per the documentation) – Anya Shenanigans Mar 07 '11 at 09:25
1

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.

dotminic
  • 1,135
  • 2
  • 14
  • 28