DirectInput8Create failure...

Started by
29 comments, last by Muhammad Haggag 18 years, 7 months ago
I'm making a game using DirectX 9.0c. The game uses directinput8, which has managed brilliantly not to work XD. Quite frustrating really. It compiles and executes for the following class (made as a standard DX input wrapper): CDx_Input.cpp:

// Use DirectInput 8 to correspond to the rest of our program (uses DirectX 9.0c)
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include "stdafx.h"
#include "CDx_Input.h"
#include "CONSTANTS.h"
#include "Log.h"

CDx_Input::CDx_Input(void)
{
	//m_lpDI8 = NULL;
	//m_mouse = NULL;
	//m_keyboard = NULL;
}

CDx_Input::~CDx_Input(void)
{
	Close();
}

HRESULT CDx_Input::Init_DirectInput(void)
{
	HRESULT hr = S_OK;

	// This command is FAILING for some reason.
	hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_lpDI8, NULL);

	if(SUCCEEDED(hr))
		Write_Log(E_NONE, "Succeeded in instantiating DirectInput8 on startup.");
	else
		Write_Log(E_FATAL, "Failed to instantiate DirectInput8 on startup!");

	// Return.
	return hr;
}

**snip**

CDx_Input.h:

#ifndef _DIRECTXMANAGERS_CDXINPUT_H
#define _DIRECTXMANAGERS_CDXINPUT_H

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

// Define button is down and button is released.  Button released is just the opposite of button down.
#define KeyDown(name, key) ((name[key] & 0x80) ? true : false)
#define KeyUp(name, key)((name[key] & 0x80) ? false : true)

class CDx_Input
{
public:
	CDx_Input(void);
	~CDx_Input(void);

	HRESULT Init_DirectInput(void);
	HRESULT Init_Keyboard(HWND hWnd);
	HRESULT Init_Mouse(HWND hWnd);
	void Update(void);
	void Close(void);

private:
	LPDIRECTINPUT8         m_lpDI8;
	IDirectInputDevice8*   m_keyboard;
	IDirectInputDevice8*   m_mouse;
};

#endif // _DIRECTXMANAGERS_CDXINPUT_H

For some bizarre reason, DirectInput8Create repeatedly fails and returns "E_POINTER" - which would seem to indicate an invalid pointer, however, having found no information on the web about a method to pre-create LPDIRECTINPUT8, I don't know why I'd be getting this problem. Any help would be *awesome*. ...oh, and a shout out there to Jim Adams - I love your book "Programming Role Playing Games with DirectX" :)
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
Advertisement
Make sure that GetModuleHandle's returning a valid instance handle (i.e. not NULL). Everything else looks Ok. Also, make sure you enable the debug runtime, and check your debug output - it'll provide messages detailing what the problem is.

That's funny... it (GetModuleHandle(NULL)) seems to be returning a valid(ish) handle...

"- hMod 0x00400000 {unused=9460301 } HINSTANCE__ *"

'course, I don't reallly know what that means. I tried enabling directx debug but it didn't seem to provide any extra information :S
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
Quote:Original post by HeavyBlade
That's funny... it (GetModuleHandle(NULL)) seems to be returning a valid(ish) handle...

"- hMod 0x00400000 {unused=9460301 } HINSTANCE__ *"

'course, I don't reallly know what that means. I tried enabling directx debug but it didn't seem to provide any extra information :S

Even with the DInput debug level slider maxed?

Quote:Original post by Coder
Quote:Original post by HeavyBlade
That's funny... it (GetModuleHandle(NULL)) seems to be returning a valid(ish) handle...

"- hMod 0x00400000 {unused=9460301 } HINSTANCE__ *"

'course, I don't reallly know what that means. I tried enabling directx debug but it didn't seem to provide any extra information :S

Even with the DInput debug level slider maxed?


Um, how do I access the DInput debug level? (oh man, that sounds lame...)
:/
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
Control Panel->DirectX, then select the DInput tab. There should be a slider to the left. Something similar to this:

Ah! Ok..
There we go!

"DINPUT8: ERROR DirectInputCreateHelper: arg 3: invalid pointer"

...but why would arg 3 be a problem?
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
The 3rd argument isn't even a pointer, so the 3rd argument in question is that of the DirectInputCreateHelper function. We don't know which one it is, though, so we'll have to do some wild guessing now. Does this code run inside a DLL?

No it doesn't. However, it does have an include for the DXUT.lib - would that be a problem?
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
Quote:Original post by HeavyBlade
No it doesn't. However, it does have an include for the DXUT.lib - would that be a problem?

No, shouldn't be a problem. This is one of them 'meh' problems, and I'm sure it'll come down to something silly in the end [smile]. Question is, what is that thing...
Have you tried to build one of the DInput samples? Do they work out of the box? Do they work if you build them?

This topic is closed to new replies.

Advertisement