• Advertisement

Archived

This topic is now archived and is closed to further replies.

Messed up Classes

This topic is 5948 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

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; };

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well, the most obvious cause would be that the DirectInput2 ptr wasn''t initialised.

Share this post


Link to post
Share on other sites

  • Advertisement