Skip to main content
gamedev.net
🔒 Locked

DirectInput8Create failure...

Started by HeavyBlade 29 replies 6.9k views
Original Post
HeavyBlade
HeavyBlade
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!
Muhammad Haggag
Muhammad Haggag
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.

HeavyBlade
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
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
Muhammad Haggag
Muhammad Haggag
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?

HeavyBlade
HeavyBlade
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!
Muhammad Haggag
Muhammad Haggag
Control Panel->DirectX, then select the DInput tab. There should be a slider to the left. Something similar to this:

HeavyBlade
HeavyBlade
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!
Muhammad Haggag
Muhammad Haggag
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?

HeavyBlade
HeavyBlade
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!
Muhammad Haggag
Muhammad Haggag
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?

HeavyBlade
HeavyBlade
Yes - following your advice I built and test ran the Action Map Basic DirectInput project - it built without a problem, and ran without a problem. o_O This is quite an annoying problem XD
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
Muhammad Haggag
Muhammad Haggag
Mmm. Ok, I'll start making things up now:
- Verify that the HINSTANCE that was passed to your WinMain is the same you get from GetModuleHandle. If not, use the one that was passed to your WinMain.

- Verify that dinput.h that the compiler sees is the right one (right-click in the IDE and open, verify the path)

HeavyBlade
HeavyBlade

The winmain hInstance:
"- hInstance 0x00400000 {unused=9460301 } HINSTANCE__ *"
The DirectInput hInstance:
"- hMod 0x00400000 {unused=9460301 } HINSTANCE__ *"

Nope, that isn't a problem...

Nope, dinput.h is included in project files as a "common" (function fails with or without this addition), and the path is valid. So I guess it's back to the.. guessing board?

Thanks for all your help btw.
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
sirob
sirob
Now that every one else has given up, it's time for me to start throwing in some of my wild ideas :).

Have you tried something like this:
	LPDIRECTINPUT8 tmpDI; // Added this line	hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&tmpDI, NULL); // and modified this one.


Or, alternatively, make sure that &m_lpDI8 is, indeed, a valid pointer.
Sirob Yes.» - status: Work-O-Rama.
HeavyBlade
HeavyBlade
Quote:
Original post by sirob
Now that every one else has given up, it's time for me to start throwing in some of my wild ideas :).

Have you tried something like this:
	LPDIRECTINPUT8 tmpDI; // Added this line	hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&tmpDI, NULL); // and modified this one.


Or, alternatively, make sure that &m_lpDI8 is, indeed, a valid pointer.


THE PLOT THICKENS, MY FRIENDS! :O

Your modification, did in fact, get DirectInput8Create to return validly.

"DINPUT8: DIHid_BuildHidList(0) ->
DINPUT8: DIHid_GetDevicePath(0015bd30, 0012F858)
DINPUT8: DIHid_GetDevicePath(0015bd30, 0012F858) -> 00000001 OK
DINPUT8: DIHid_GetDevicePath(0015bd30, 0012F858)
DINPUT8: DIHid_GetDevicePath(0015bd30, 0012F858) -> 00000001 OK
DINPUT8: DIHid_BuildHidList(0)
DINPUT8: DIHid_BuildHidList(0) -> "

...but why would it have been a problem before? and can I simply go...
"m_lpDI8 = tmpDI;" ?
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
sirob
sirob
How are you creating the "CDx_Input" object? Do you have a pointer to a CDx_Input that you're calling Init_DirectInput on? Do you ever call new on the pointer? I think you get my drift here.

Alternatively, I do remeber some problem with the LP pointers a long time ago, but that's likely to be me causing the problem. I also checked my code, it's call to call like yours, so it should work.
Sirob Yes.» - status: Work-O-Rama.
Evil Steve
Evil Steve
How do you create your CDx_Input class?

I think that you're allocating it with new, and it's failing - or it's a pointer which is invalid.
Either way, you're calling CDx_Input::Init_DirectInput() on an invalid this pointer, which would make the member variable invalid, causing DInput to scream.

What is the value of this inside your CDx_Input::Init_DirectInput() function?

Edit: Too slow.
HeavyBlade
HeavyBlade
Hmmm, well, it's called like this:

(In the constructor of GameView class):

*snip
m_pCDxInput = GCC_NEW CDx_Input;
*snip

(and in the VCreateGameAndView function):

{
// Make sure to clear our log and everything.
gameView->Startup_GlobalInit();

// Initialize our window and directX.
m_CGameWindow->Init_Window(&hWnd, MsgProc, "DotS", "Dawn of the Shards");

// Initialize direct input.
gameView->m_pCDxInput->Init_DirectInput();
gameView->m_pCDxInput->Init_Keyboard(hWnd);
gameView->m_pCDxInput->Init_Mouse(hWnd);

// Initialize Direct Draw.
gameView->Game_Init_DirectX_gfx();
}

Plz forgive lack of code wrapping, but it's not a lot of code XD.

That shouldn't be problematic though, should it? (btw, gameView is created just prior to the code shown above).

EDIT: Ah! The value of this inside CDx_Input::Init_DirectInput(void) is:
"- this 0xcdcdcdcd {m_lpDI8=??? m_keyboard=??? m_mouse=??? } CDx_Input * const"
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!
sirob
sirob
Well, I don't know what GCC_NEW is, but if that's not it, you might not be calling the constructor. Something is definatly wrong there.
Sirob Yes.» - status: Work-O-Rama.
HeavyBlade
HeavyBlade
Man... I love you guys.. (er, in the perfectly normal way) :D

// Game Code Complete - Chapter 12, page 446-447
#if defined(_DEBUG)
# define GCC_NEW new(_NORMAL_BLOCK,__FILE__, __LINE__)
#else
# define GCC_NEW new
#endif
Join us at: http://www.blade2k.net/piracysucks/to help stop game piracy!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.