CFileDialog.DoModal() Crashes When Hint box is about to appear.

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 ext

NULL , // initial file name

OFN_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!



Answer this question

CFileDialog.DoModal() Crashes When Hint box is about to appear.

  • rksty

    My problem turned out to be nothing to do with my software, but a Windows bug caused by some sort of interaction between Windows XP and Adobe Reader 7.0. It's all documented at http://support.microsoft.com/kb/909486/en-us A Hotfix is available to sort it out if it turns out to be the same problem. Try to simulate the fault in Notepad as follows: Create a file with an unregistered file suffix (I used .rpb). Open Notepad. Enter File-> Open, navigate to the file and hold your mouse pointer over the file name until the little hint box appears. Cancel, then repeat the process - File -> Open and hold your mouse pointer over the file. If it's the same problem NotePad will crash out.
  • Phil Doucette

    Your code fragment is fine and wouldn't cause the heap damage. It is the code that runs between the first call to this fragment and the second call. Look for anything suspicious in the way you handle pointers. Check this MSDN library topic for ways to turn on the debug memory allocator.


  • mball

    Great! You managed to isolate the problem. Heap corruption is getting unlikely. More things to try:
    - Display the hint twice in the 1st dialog
    - Display a hint on a file other than a .SLG file in the 1st dialog



  • Mike Turner - MSFT

    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.


  • Rob-C

    First check if the HKCR\.slg and HKCR\SLGFile registry keys look OK. Next, try moving just this code into a separate test program and see if it still happens. That would eliminate the possibility that other code in your program destroyed the heap. If the test program works OK, try using the debug memory allocator.


  • Sergio VB

    Well, that proves it for me. You need the Geek squad, not this forum. Good luck.


  • Greg4

    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


  • StefanoUD

    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.


  • NTx Beta

    Ok, I'm starting to reach for straws. Since it crashes on unregistered file types, I don't think it is a problem with the .SLG filetype registration. If the registry would be damaged to the point that enumerating keys in the HKCR hive won't work anymore, you should see a lot of other problems.

    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...



  • sriksdave

    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.


  • Jrt

    Well, thanks for all your help. I'll see what the Geek squad can do for me.
  • eran koren

    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


  • CFileDialog.DoModal() Crashes When Hint box is about to appear.