Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Unhandled Exception-0xC0000005:Access Violation

Unhandled Exception-0xC0000005:Access Violation

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebugging
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rsh
    wrote on last edited by
    #1

    My program creates an object of CList, the nodes of which contains CMessage class object. The file has two functions, Write2List() and ReadFromList().After executing the program,i get no errors. But if i debug the program, i get "Unhandled Exception-0xC0000005:Access Violation" error after coming out of the ReadFromList(). Please help. The code is as follows include #include #include class CMessage { public: unsigned char m_cnt, m_mid; public: //constructor CMessage(); CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pdata); //destructor ~CMessage(); void SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata); int GetData(unsigned char* pdata); private: unsigned char m_data[4]; //body of the message }; CMessage::CMessage() { } CMessage::CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pData) : m_cnt(nCnt), m_mid(nMid) { for(int i=0; i <= ( m_cnt - 2); i++) m_data[i] = *pData++; } CMessage::~CMessage() { // m_cnt = '\0'; // m_mid = '\0'; // memcpy(m_data,'\0',16); } void CMessage::SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata) { m_cnt = nCnt; m_mid = nMid; for(int i=0; i <= ( m_cnt - 2); i++) m_data[i] = *pdata++; } int CMessage::GetData(unsigned char* pdata) { for(int i=0; i <= ( m_cnt - 2 ); i++) *pdata++ = m_data[i]; return 0; }//end of class CMessage //typedef for our list template. //Type is CMessage CList myList; void Write2List()//CMessage* pMessage1) { unsigned char data[4]; data[0] = 0x01; data[1] = 0x02; data[2] = 0x00; data[3] = 0x04; //first time of Initialisation CMessage* pMessage = new CMessage(); //setting values thru the function. pMessage->m_cnt = 0x40; pMessage->m_mid = 0x30; pMessage->SetValues(0x20,0x41,data); myList.AddTail(*pMessage); } void ReadFromList() { unsigned char data[10], mCnt,mMid; CMessage pMess; while(myList.GetCount() != 1) { pMess = myList.GetAt(myList.GetHeadPosition()); mCnt = pMess.m_cnt; mMid = pMess.m_mid; pMess.GetData(data); myList.RemoveHead(); } cout<<"abc"<

    J 1 Reply Last reply
    0
    • R Rsh

      My program creates an object of CList, the nodes of which contains CMessage class object. The file has two functions, Write2List() and ReadFromList().After executing the program,i get no errors. But if i debug the program, i get "Unhandled Exception-0xC0000005:Access Violation" error after coming out of the ReadFromList(). Please help. The code is as follows include #include #include class CMessage { public: unsigned char m_cnt, m_mid; public: //constructor CMessage(); CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pdata); //destructor ~CMessage(); void SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata); int GetData(unsigned char* pdata); private: unsigned char m_data[4]; //body of the message }; CMessage::CMessage() { } CMessage::CMessage(unsigned char nCnt, unsigned char nMid, unsigned char* pData) : m_cnt(nCnt), m_mid(nMid) { for(int i=0; i <= ( m_cnt - 2); i++) m_data[i] = *pData++; } CMessage::~CMessage() { // m_cnt = '\0'; // m_mid = '\0'; // memcpy(m_data,'\0',16); } void CMessage::SetValues(unsigned char nCnt, unsigned char nMid, unsigned char* pdata) { m_cnt = nCnt; m_mid = nMid; for(int i=0; i <= ( m_cnt - 2); i++) m_data[i] = *pdata++; } int CMessage::GetData(unsigned char* pdata) { for(int i=0; i <= ( m_cnt - 2 ); i++) *pdata++ = m_data[i]; return 0; }//end of class CMessage //typedef for our list template. //Type is CMessage CList myList; void Write2List()//CMessage* pMessage1) { unsigned char data[4]; data[0] = 0x01; data[1] = 0x02; data[2] = 0x00; data[3] = 0x04; //first time of Initialisation CMessage* pMessage = new CMessage(); //setting values thru the function. pMessage->m_cnt = 0x40; pMessage->m_mid = 0x30; pMessage->SetValues(0x20,0x41,data); myList.AddTail(*pMessage); } void ReadFromList() { unsigned char data[10], mCnt,mMid; CMessage pMess; while(myList.GetCount() != 1) { pMess = myList.GetAt(myList.GetHeadPosition()); mCnt = pMess.m_cnt; mMid = pMess.m_mid; pMess.GetData(data); myList.RemoveHead(); } cout<<"abc"<

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      pMessage->SetValues(0x20,0x41,data);

      This line in Write2List seems to indicate that data is 0x20-2=20 bytes long, yet it contains only 4 bytes. This might be causing the error. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      R 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        pMessage->SetValues(0x20,0x41,data);

        This line in Write2List seems to indicate that data is 0x20-2=20 bytes long, yet it contains only 4 bytes. This might be causing the error. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        R Offline
        R Offline
        Rsh
        wrote on last edited by
        #3

        Thank u very much for ur help. Now it is working fine :) Roopa

        J 1 Reply Last reply
        0
        • R Rsh

          Thank u very much for ur help. Now it is working fine :) Roopa

          J Offline
          J Offline
          Jim Crafton
          wrote on last edited by
          #4

          As an aside, it would make your life a lot easier if you use STL for your collection classes inside of the MFC collection junk.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups