Click here to Skip to main content
15,915,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: stl iterator Pin
John M. Drescher6-Jun-02 6:28
John M. Drescher6-Jun-02 6:28 
GeneralRe: stl iterator Pin
Mike Nordell6-Jun-02 10:22
Mike Nordell6-Jun-02 10:22 
GeneralRe: stl iterator Pin
John M. Drescher6-Jun-02 10:21
John M. Drescher6-Jun-02 10:21 
GeneralSysListView32 (Desktop) Pin
[xan]6-Jun-02 2:01
[xan]6-Jun-02 2:01 
GeneralProblem with Adobe SVG ActiveX Pin
6-Jun-02 1:33
suss6-Jun-02 1:33 
GeneralPCM To True Speech WAV Conversion Pin
AJ1235-Jun-02 22:52
AJ1235-Jun-02 22:52 
GeneralRe: PCM To True Speech WAV Conversion Pin
NotYourAverageGuy6-Jun-02 8:12
NotYourAverageGuy6-Jun-02 8:12 
GeneralUnhandled Exception-0xC0000005:Access Violation Pin
Rsh5-Jun-02 22:08
Rsh5-Jun-02 22:08 
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 <memory.h>
#include <afxtempl.h>
#include <iostream.h>


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<CMessage, CMessage&> 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"<<endl;
cout<<(int)data[0]<<endl;

}


void main()
{
Write2List();
Write2List();
cout<<"ABC"<<endl;
ReadFromList();
cout<<"XYZ";


}


Roopa
GeneralRe: Unhandled Exception-0xC0000005:Access Violation Pin
Joaquín M López Muñoz5-Jun-02 22:12
Joaquín M López Muñoz5-Jun-02 22:12 
GeneralRe: Unhandled Exception-0xC0000005:Access Violation Pin
Rsh6-Jun-02 1:40
Rsh6-Jun-02 1:40 
GeneralRe: Unhandled Exception-0xC0000005:Access Violation Pin
Jim Crafton6-Jun-02 3:25
Jim Crafton6-Jun-02 3:25 
GeneralSocket Question Pin
anotherocd5-Jun-02 20:35
anotherocd5-Jun-02 20:35 
GeneralRe: Socket Question Pin
6-Jun-02 2:25
suss6-Jun-02 2:25 
Generalinstead of Task schedular Pin
hex5-Jun-02 20:04
hex5-Jun-02 20:04 
QuestionRegular Expression in C++. How to? Pin
Atrament5-Jun-02 19:55
Atrament5-Jun-02 19:55 
AnswerRe: Regular Expression in C++. How to? Pin
5-Jun-02 20:11
suss5-Jun-02 20:11 
AnswerRe: Regular Expression in C++. How to? Pin
Stuart Dootson5-Jun-02 20:44
professionalStuart Dootson5-Jun-02 20:44 
GeneralRe: Regular Expression in C++. How to? Pin
Mike Nordell6-Jun-02 3:36
Mike Nordell6-Jun-02 3:36 
AnswerRe: Regular Expression in C++. How to? Pin
Ernest Laurentin6-Jun-02 10:12
Ernest Laurentin6-Jun-02 10:12 
AnswerRe: Regular Expression in C++. How to? Pin
Atrament7-Jun-02 17:35
Atrament7-Jun-02 17:35 
GeneralRe: Regular Expression in C++. How to? Pin
Stuart Dootson9-Jun-02 15:33
professionalStuart Dootson9-Jun-02 15:33 
Generalactiveskin4.1 Pin
sai5-Jun-02 19:43
sai5-Jun-02 19:43 
GeneralRendering a bitmap on a CView Pin
Nish Nishant5-Jun-02 19:35
sitebuilderNish Nishant5-Jun-02 19:35 
GeneralRe: Rendering a bitmap on a CView Pin
Michael Dunn5-Jun-02 19:41
sitebuilderMichael Dunn5-Jun-02 19:41 
GeneralRe: Rendering a bitmap on a CView Pin
Nish Nishant5-Jun-02 19:54
sitebuilderNish Nishant5-Jun-02 19:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.