Jump to content
  • Advertisement
Sign in to follow this  
HeavyBlade

DirectInput8Create failure...

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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" :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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...)
:/

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!