I have a strange crashing problem in an application developed on Visual Studio 2005 Standard Edition.
The crash comes during a function call to CFileDialog.DoModal(). The problem seems to relate to the "hint" box that appears if you let the mouse pointer linger over a file. If the mouse pointer registers over a file with an unregistered file type, then a hint box appears indicating the file type (e.g. ".slg file"). You then open the file with no problem. If you then go to open a file again using the same CFileDialog.DoModal() function and let the pointer linger over the file, then after a few seconds, just as the hint box would have appeared, the program crashes out with an Unhandled Exception error. This crash is absolutely repeatable.
Does anyone out there have any idea what could be causing the crash I have spent days trying to find what's wrong and can't find anything. I have copied an excerpt of code and the error message below.
Hope someone can help!
|
Unhandled exception at 0x7ca51406 in MS300 Countersurveillance System.exe: 0xC0000005: Access violation reading location 0x023c2038.
Code extract: static char BASED_CODE szFilter[] = "Carrier Log File (*.slg)|*.slg|All Files (*.*)|*.*||"; CFileDialog FileDialog ( true , // true is for read ".slg" , // def extNULL , // initial file nameOFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter , NULL ); if(FileDialog.DoModal() == IDOK) // Code crashes here in DoModal// Code only crashes the second time CFileDialog is used // Code crashes at the moment when the hint box is to be displayed. // If the user selects the file quickly so that hint box does not appear, no crash! |

CFileDialog.DoModal() Crashes When Hint box is about to appear.
Sneath
- Display the hint twice in the 1st dialog
- Display a hint on a file other than a .SLG file in the 1st dialog
rjnealtx
I'm glad you think I'm getting closer - I just get more confused!
1. I can display the hint as many times as I want in the first dialog with no problems.
2. Windows registered file types like .wav files .doc files don't seem to cause any problems. Any unregistered file types (I just created a file with the extension .lvf). cause DoModal to crash. The file types used by my program have been entered in the registry using the File Types editor in Visual Studio, but they still cause crashes. Could it be a registry problem
Thanks again for your help.
shine
tizzdale27
More things to try:
1. Run Notepad and use File + Open to see if it has problems too.
2. Try running your program on another PC to see if the problem is isolated to your PC only.
If it works OK on another PC, you might be suffering from DLL hell. I think the common dialog boxes live in comdlg32.dll. Unfortunately, it loads a bunch of other DLLs as well (see for yourself with Dependency Walker). The one that made me sit up is RichEd20.dll, I've seen DLL hell problems with that one before...
pgyb
The registry looks OK. When I copy the code into a test program that seems to work OK. I notice that the same error occurs when opening files using the FileOPen commands produced by VisualStudio (i.e. CWinApp::OnFileOpen. So something is destroying the heap memory I don't understand how this could happen as there are only a few lines of code between creating the CFileDialog object and calling DoModal.
How can I track this down Are there tools which allow me to see where Heap memory is allocated and destroyed. Any help would be much appreciated.
eyekron
jessetechie
Lianne
I thought I found the solution: call CoInitializeEx() at application (thread) startup, and CoUninitialize() at application (thread) termination.
But that doesn't seem to be the solution. Has anybody a work-around for this bug
Togo
a9192shark
How strange! The same thing happens in NotePad, except that I don't get the exception error, NotePad just disappears.
I don't have access to another PC until Monday, but I've tried my software on different PCs before, with exactly the same problem.
I thought that dll hell had been cured on Windows XP, no
Will Barns
Rupesh Kumar
Sepultang
Thanks for all your help, it's been invaluable.
I have looked at the Heap and I can't see any problem. I modified the code to put two CFileDialog.DoModal() commands straight after each other. As expected, the first one runs OK, but the second one crashes out as the hint box is about to appear(this only happens if the pointer was held over the file name long enough for the hint box to appear the previous time it was run).
I then took memory snapshots before the first DoModal and the second and compared them. No difference. The only difference was 3 free blocks (presumably DoModal allocated and destroyed three blocks). The program still crashed out. The modified code and debugger output are below.
Hope you might have some more hints.
Code:
CMemoryState oldMemState, newMemState, diffMemState;
oldMemState.Checkpoint();
oldMemState.DumpStatistics();
FileDialog.DoModal();
newMemState.Checkpoint();
newMemState.DumpStatistics();
if( diffMemState.Difference( oldMemState, newMemState ) ){
TRACE(
"Memory Change!\n" );}
diffMemState.DumpStatistics();
FileDialog.DoModal();
Debug Output:
Before first DoModal()
2754253 bytes in 816 Free Blocks.
13893 bytes in 33 Normal Blocks.
7899 bytes in 44 CRT Blocks.
0 bytes in 0 Ignore Blocks.
5737120 bytes in 22 Client Blocks.
Largest number used: 7319097 bytes.
Total allocations: 27525078 bytes.
Before second DoModal()
2754289 bytes in 819 Free Blocks.
13893 bytes in 33 Normal Blocks.
7899 bytes in 44 CRT Blocks.
0 bytes in 0 Ignore Blocks.
5737120 bytes in 22 Client Blocks.
Largest number used: 7319097 bytes.
Total allocations: 27525114 bytes.
Difference
36 bytes in 3 Free Blocks.
0 bytes in 0 Normal Blocks.
0 bytes in 0 CRT Blocks.
0 bytes in 0 Ignore Blocks.
0 bytes in 0 Client Blocks.
Largest number used: 0 bytes.
Total allocations: 36 bytes.