Problem with DirectInput8Create

Started by
12 comments, last by Harvester944 19 years ago
Well, here is the problem, plain and simple. the code below, when compiled, comes up with "c:\Program Files\microsoft directx 9.0 sdk(febuary 2005)\include\dinput.h: DIRECTINPUT_VERSION undefined. defaulting to 0x0800" and no further problems. However, when it is run, it always gives me the message box "DirectInput8Create has failed". So far, I have been unable to figure out why it is doing this, other than the obvious fact that DirectInput8Create is not returning a positive hResult.

// this is the hResult variable
HRESULT hResult;

// create the DirectInput object
hResult = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8,     
                             (void**)&DirectInputObject, NULL);

// check to make sure that creation of the direct input object was succesful
if (FAILED ( hResult ) )
{
   MessageBox(NULL, "DirectInput8Create has failed", "Error", MB_OK);
   return false;
}
All help is appreciated, thank you -Harvester944
Advertisement
Try comparing hResult to one of these 4 error values and then reply with your results:
DIERR_BETADIRECTINPUTVERSIONDIERR_INVALIDPARAMDIERR_OLDDIRECTINPUTVERSIONDIERR_OUTOFMEMORY
Is your hInstance parameter valid?
If not you can always grab the instance of the Foreground Window by calling GetModuleHandle(NULL)
Thank you for your fast replies.

I compared the hResult variable to the four that JClayton gave, and it turned up with "DIERR_INVALIDPARAM". Wondering if my hInstance might be invalide after all, I replaced hInstance with GetModuleHandle(NULL). I now get the "program has encounterd a problem and needs to close. We are sorry for the inconvenience..." ect. This happens before any message boxes appear. I checked back in the earlier code and found I was passing the hInstance variable to my DirectInputInitialization function incorrectly. When changed so that it is passed correctly, I get the same problem as when I use GetModuleHandle(NULL) Any ideas?

-Harvester944
I had a similar problem with initialising DirectInput - have you left out the following define?

#define DIRECTINPUT_VERSION 0x0800

...make sure its included or it won't work. ^_^

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

Have you tried doing Rebuild All? Do you have a debugger you can use? Taht should give you more information than "This program has encounterd a problem and needs to close". What compiler are you using?
I am afraid that #define DIRECTINPUT_VERSION 0x0800 didn't work, it is also defined in the header file (dinput.h). I tried rebuild all, same problem. Running the debugger causes a pop-up window to appear which says :
"Unhandled exception at 0x00413385 in program.exe: 0xC0000005: Access violation reading location 0x00000000." Selectiong break leaves me with a large yellow arrow pointing at this line of code :

DirectInputDevice->GetDeviceState( sizeof(buffer), (LPVOID)&buffer );

I am using Microsoft Visual Studio .NET 2003

Thanks for your replies.

-Harvester944
So, is it getting past the DirectInput8Create() call now, and failing when you get the device state? Perhaps the device is unacquired/lost?

Do you have all the debugging levels turned up to the max in the DirectX control panel etc. If you turn those up it might give you more helpful error messages (assuming you run from within the debugger).

EDIT: Your buffer parameters look a little suspect - what device is that for & how are they declared?

-Mezz
Quote:Original post by Harvester944
"Unhandled exception at 0x00413385 in program.exe: 0xC0000005: Access violation reading location 0x00000000." Selectiong break leaves me with a large yellow arrow pointing at this line of code :

DirectInputDevice->GetDeviceState( sizeof(buffer), (LPVOID)&buffer );
reading location 0x00000000. - That's a NULL pointer. And the only thing on that line that can be NULL is DirectInputDevice. So either your device setup is failing, or you're releasing your device accidently, after allocating it.

EDIT: Actually, if buffer is a member variable, and is the first variable in your class, then your this pointer could be NULL. Although I very much doubt that you'd have the buffer as a member variable in your class.

This topic is closed to new replies.

Advertisement