mfc application dosent work thru exe

hi. i have created an mfc application using visual studio 2003. it runs fine when i debug it thru the studio, but when i try to run the exe which is created in the debug folder as a result of building the application, it throws the following error :

"abc MFC Application has encountered a problem and needs to close. We are sorry for the inconvenience."

i pressed the 'debug' button on that error message, and it points to the following piece of code :

while(!feof(fp)){


where 'fp' is a file pointer. and the message is :

"unhandled exception at 0X00402919 in anc.exe : 0XC0000005 : Access violation reading location 0X0000000c."

now obviously this means that its trying to read some memory location pointed to by the file pointer, it cant do so , and throws an exception. but , firstly, how is it working thru the debugger then ? and secondly, i have no idea what memory location its unable to read .

please let me know if you have any suggestions or solutions . thanks .


[1111 byte] By [vishal1857] at [2007-12-16]
# 1
vishal1857 wrote:
firstly, how is it working thru the debugger then ?
There's a couple of ways the debugger might mask this sort of problem.

For example, running inside the debugger causes memory to be allocated differently. Just by random chance it could be that the memory the bad address in your file pointer is pointing at is readable memory when run inside the debugger and is a piece of memory you are not allowed to read when run outside of the debugger. In both cases you are pointing at the wrong address, but only the non-debugger case would throw an access violation exception.

I don't think that's what is happening to you however. The address you are trying to access is 0x0000000C which should always be not readable.

Another possibility is that the bad address you are trying to access is different in the debugger and non-debugger case. In the debugger case the bad address is not 0x0000000C and whatever value it does have, that memory is readable so again you don't get an access violation.

A third possibility is that the debugger is having an effect even earlier in your code such that when run inside the debugger fp contains a valid file pointer and when executed outside the debugger fp does not contain a valid file pointer.

and secondly, i have no idea what memory location its unable to read
I don't think you should worry too much about the specific memory location being accessed. Just consider the fp file pointer broken and try to figure out why it is broken.

For example, are you sure the file pointer is being opened correctly? Are you sure it isn't being closed by some other piece of code before feof is called?


FrankBoyne at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ General...