Messed up Classes
heres the code.
#include "DirectInput.h"
#include "DIKeyboard.h"
class DInput;
DIKeyboard::DIKeyboard()
{
Acquired = false;
DIDevice = NULL;
}
DIKeyboard::~DIKeyboard()
{
if(DIDevice)
CleanUp();
}
bool DIKeyboard::Create()
{
HRESULT hr = DI_OK;
DInput *di;
DirectInput=di;
hr = DirectInput2->CreateDevice(GUID_SysKeyboard, &DIDevice, NULL);
// Set the keyboard object in the SDXInput object
DirectInput->DIKeyboard = this;
/*
hr = DIDevice->SetDataFormat(&DIKeyboard);
if FAILED(hr)
{
return false;
}
*/
// Set the cooperative level
hr = DIDevice->SetCooperativeLevel(DirectInput->hwnd,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if FAILED(hr)
{
return false;
}
return true;
}
void DIKeyboard::CleanUp()
{
// release the DInput object
DIDevice->Release();
DIDevice = NULL;
}
bool DIKeyboard::Update()
{
HRESULT hr = DI_OK;
if(!Acquire())
return false;
hr = DIDevice->GetDeviceState(256, (LPVOID)SnapshotBuffer);
if FAILED(hr)
{
if(hr == DIERR_INPUTLOST)
{
if(!Acquire())
{
return FALSE;
}
}
else
{
return FALSE;
}
}
return TRUE;
}
bool DIKeyboard::Acquire()
{
HRESULT hr = DIDevice->Acquire();
if FAILED(hr)
{
return false;
}
else
{
Acquired = true;
return true;
}
}
bool DIKeyboard::Unacquire()
{
HRESULT hr = DIDevice->Unacquire();
if FAILED(hr)
{
return false;
}
else
{
Acquired = false;
return true;
}
}
#include
class DIKeyboard
{
public:
DIKeyboard();
virtual ~DIKeyboard();
// make sure the original COM object pointer is accessible
inline LPDIRECTINPUTDEVICE Obj()
{
return DIDevice;
}
inline operator LPDIRECTINPUTDEVICE()
{
return DIDevice;
}
bool Create();
void CleanUp();
inline bool IsActive()
{
return (DirectInput) ? true : false;
}
LPDIRECTINPUT DirectInput2;
bool Acquire();
bool Unacquire();
inline bool IsAcquired()
{
return Acquired;
}
bool Update();
inline bool IsKeyPressed(unsigned char c)
{
return (SnapshotBuffer[c] & 0x80 ) ? true : false;
}
BYTE SnapshotBuffer[256];
DInput* DirectInput;
LPDIRECTINPUTDEVICE DIDevice;
bool Acquired;
};
Perhaps it would help if you told us exactly what''s wrong. Does your program not run? Do you get error messages?
~~~~~~~~~~
"Usewhitespacetoenhancereadability" - Steve McConnell, Code Complete
~~~~~~~~~~
"Usewhitespacetoenhancereadability" - Steve McConnell, Code Complete
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement