Original Post
I am making a basic framework that I can just use for making any type of game using the Allegro graphics library. Right now it has a message handler class, application class, and event handler class. I got the idea from an SDL book I read, but changed it quite a bit. Here is all the code that relates to the problem. ~~MessageHandler.h~~ //include guards #ifndef MESSAGEHANDLER_H #define MESSAGEHANDLER_H #include "allegro.h" //the message ID variable typedef unsigned int MSGID; //the message parameter variable typedef void *MSGPARM; /* CMessageHandler makes it easy for classes to communicate with each other. It handles the setting of message IDs, the parameters that go with the messages, and the sending and handling of messages. */ class CMessageHandler { private: static MSGID m_nextMSGID; public: //handles messages, this is meant to be overidden virtual bool OnMessage(MSGID msgID, MSGPARM parm1, MSGPARM parm2, MSGPARM parm3, MSGPARM parm4, MSGPARM parm5); //sends messages bool SendMessage(MSGID msgID, MSGPARM parm1, MSGPARM parm2, MSGPARM parm3, MSGPARM parm4, MSGPARM parm5); //gets a new MSGID static MSGID GetNextMSGID(); }; #endif ~~MessageHandler.cpp~~ #include "messagehandler.h" //sets the message ID to 0 MSGID CMessageHandler::m_nextMSGID = 0; //this returns a new message ID for a message MSGID CMessageHandler::GetNextMSGID() { //return a new MSGID return(m_nextMSGID++); } //sends messages (I think this function has something to do with the access violation) bool CMessageHandler::SendMessage(MSGID msgID, MSGPARM parm1, MSGPARM parm2, MSGPARM parm3, MSGPARM parm4, MSGPARM parm5) { //process the message if(OnMessage(msgID,parm1,parm2,parm3,parm4, parm5)) { return(true); } //if the message is unknown else { return(false); } } //handles messages, meant to be overidden bool CMessageHandler::OnMessage(MSGID msgID, MSGPARM parm1, MSGPARM parm2, MSGPARM parm3, MSGPARM parm4, MSGPARM parm5) { //returns true by default return(true); } ~~EventHandler.h~~ //include guards #ifndef EVENTHANDLER_H #define EVENTHANDLER_H #include "application.h" #include "messagehandler.h" /* CEventHandler handles all keyboard, mouse, and custom events */ class CEventHandler : public CMessageHandler { public: //check for events void CheckEvent(); //keyboard events void OnKeyDown(); void OnKeyUp(); //mouse events void OnMouseMove(); void OnLButtonDown(); void OnRButtonDown(); void OnLButtonUp(); void OnRButtonUp(); //handles messages bool OnMessage(MSGID msgID, MSGPARM parm1, MSGPARM parm2, MSGPARM parm3, MSGPARM parm4, MSGPARM parm5); //messages static MSGID MSGID_EXIT; }; #endif ~~EventHandler.cpp~~ #include "eventhandler.h" //get message IDs MSGID CEventHandler::MSGID_EXIT = CMessageHandler::GetNextMSGID(); void CEventHandler::CheckEvent() { if(keypressed()) OnKeyDown(); if(mouse_b&1) OnLButtonDown(); if(mouse_b&3) OnRButtonDown(); } void CEventHandler::OnKeyDown() { int keyVal; keyVal = readkey(); if ((keyVal >> 8) == KEY_ESC) { //SendMessage is what is causing the access violation, it really shouldn't have to do with MSGID_EXIT being NULL because that wouldn't effect it. It must be the SendMessage function, from what I see. SendMessage(MSGID_EXIT, NULL, NULL, NULL, NULL, NULL); } } void CEventHandler::OnMouseMove() { } void CEventHandler::OnLButtonDown() { } void CEventHandler::OnRButtonDown() { } bool CEventHandler::OnMessage(MSGID msgID, MSGPARM parm1, MSGPARM parm2, MSGPARM parm3, MSGPARM parm4, MSGPARM parm5) { if(msgID == MSGID_EXIT) { CApplication::GetApp()->Exit(); return(true); } else { return(false); } } It seems I cant make anything without having these access violation problems and can never seem to fix them myself, I really don't like always having to always post in the forums for help, but I don't know what else to do. It's kind of discouraging not being able to fix your own problems, for me anyway. Any help and an explaination of why the access violation was caused would be great. Thanks in advance. P.S. How do you put the code in those neat litte boxes so the formatting and colors stay nice and readable?