Code:
CMything cmThing[5];
void FillData()
{
for(lCount=0;lCount<5;lCount++)
{
cmThing[lCount].SetCC("Jeff Lenoce");
cmThing[lCount].Setl1(lCount*2);
cmThing[lCount].Setl2(cmThing[lCount].Getl1()+1);
cmThing[lCount].Setl3(cmThing[lCount].Getl2()+1);
cmThing[lCount].SetRC(0,0,32,32);
}
}
void SaveData()
{
lSize=sizeof(CMything);
ULONG fp=0;
HANDLE hFile=CreateFile("cmThings.dat",GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
for(lCount=0;lCount<5;lCount++)
{
fp=lCount*lSize;
WriteFile(hFile,&cmThing[lCount],lSize,&fp,NULL);
}
CloseHandle(hFile);
}
void ReadData()
{
lSize=sizeof(CMything);
ULONG fp=0;
HANDLE hFile=CreateFile("cmThings.dat",GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
for(lCount=0;lCount<5;lCount++)
{
fp=lCount*lSize;
ReadFile(hFile,&cmThing[lCount],lSize,&fp,NULL);
}
CloseHandle(hFile);
}
void DisplayData()
{
char cL1[20], cL2[20], cL3[20], cCount[20];
char cRL[20], cRT[20], cRR[20], cRB[20];
char cSep[5]=" - ";
RECT rcTest;
for(lCount=0;lCount<5;lCount++)
{
char cCat[10]="My Thing";
_ltoa(cmThing[lCount].Getl1(),cL1,10);
_ltoa(cmThing[lCount].Getl2(),cL2,10);
_ltoa(cmThing[lCount].Getl3(),cL3,10);
CopyRect(&rcTest,cmThing[lCount].GetRC());
_ltoa(rcTest.left,cRL,10);
_ltoa(rcTest.top,cRT,10);
_ltoa(rcTest.right,cRR,10);
_ltoa(rcTest.bottom,cRB,10);
_ltoa(lCount,cCount,10);
strcat(cCat," = ");
strcat(cCat,cCount);
strcat(cCat,"\n");
strcat(cCat,"Longs:");
strcat(cCat,"\n");
strcat(cCat,cL1);
strcat(cCat,"\n");
strcat(cCat,cL2);
strcat(cCat,"\n");
strcat(cCat,cL3);
strcat(cCat,"\n");
strcat(cCat,"RECTs");
strcat(cCat,"\n");
strcat(cCat,cRL);
strcat(cCat,"\n");
strcat(cCat,cRT);
strcat(cCat,"\n");
strcat(cCat,cRR);
strcat(cCat,"\n");
strcat(cCat,cRB);
MessageBox(NULL,cCat,"Debug",NULL);
}
}
Everything works fine until I run DisplayData(). It goes through the for loop fine until it get to (lCount==4) and then I get an invalid page fault error.