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!