I just spent a week debugging this program...got it working, and made a big no no in my code, im reading files into a variable (char * szBuffer in a loop, one at a time) returning the variable to null after each execution, however the variable i'm creating is (according to the compiler) too big for the heap(4294967295 bytes or bits it doesn't say). And it is, it was huge. So, heres some code...any suggestions on how to adjust my variable usage so i don't overload the heap?
Code:
while(stillFiles==1){
tempFileName=fileData.cFileName;
GetFullPathName(tempFileName,nBufferLength,tempFilePathBuffer,&tempFilePath);
if(FindNextFile(hFileRead,&fileData)==0){
stillFiles=0;
ErrorTeller("Search Complete");
}else{
stillFiles=1;
}
//IF THERE ARE MORE FILES
if(stillFiles==1){
hFileRead = CreateFile(tempFilePath, // open found file
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFileRead == INVALID_HANDLE_VALUE)
{
ErrorHandler("Could Not Open File"); // process error
}
//OPEN THESE
fileSize=GetCompressedFileSize(tempFilePath,NULL);//still not sure about this function, use compressed or uncompressed??
LPDWORD lpNumberOfBytesRead=new unsigned long;
int MAXSIZE=static_cast <int> (fileSize);
char * szBuffer=new char[MAXSIZE];
if(ReadFile(hFileRead,szBuffer,0,lpNumberOfBytesRead,NULL)==0){
ErrorHandler("Could Not Read File"); //process error
}
CharUpper(szBuffer);
a = strchr(szBuffer, '(' );
if (strchr(szBuffer,'(')==NULL) {
stop=1;
}else{
stop=0;
}
if (stop!=1){
b=strtok(a,")");
}
if (strstr(b,partNumber)!=NULL) {
cout<<"That Part Was Found In: "<<tempFilePath<<endl;
cout<<'\"'<<b<<'\"'<<endl;
fout<<"That Part Was Found In: "<<tempFilePath<<endl;
fout<<'\"'<<b<<'\"'<<endl;
foundOnce=1;
szBuffer=NULL;
}
}
}
thanks