Messed up Classes

Started by
2 comments, last by tenchimusakiryoko 22 years, 5 months ago
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; };
"Good,evil,I got the gun"Ash- Evil Dead
Advertisement
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
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
sorry,my friend wanted to look at it didnt think anyone else would hehe.anyways it crashes with an access violation.the line that crashes is DirectInput->CreateDevice.thanks
"Good,evil,I got the gun"Ash- Evil Dead
Well, the most obvious cause would be that the DirectInput2 ptr wasn''t initialised.

This topic is closed to new replies.

Advertisement