Hello again, this time for a new problem with the GetOpenFileName function.
Well, I have a function which calls GetOpenFileName to retrieve a path to one to open. The problem is that sometimes, quite often, the program ends with a Access Violation exception during the execution of the common dialog; to be precise, it is after the user clicked the "ok" button, which normally close the box while sending back to the caller the file name, and before the function returns. (or at least nothing that is after the call execute)
I tried my debugger to see what was going wrong but I only saw it once but at that time I had many other errors so I left that one; every other times, the program runs well...

What could it be? What could I do?

Here's some code, maybe it could help.
Code:
/* The function takes parameters and returns 0 if no error occured, a negative value otherwise.
_trace and _tracecc are macros expanding to message boxes depending on wether I'm debugging or not.
*/
int opendlg(HWND parent, int type, const _TCHAR *title, _TCHAR *file, const _TCHAR *filt)
{
    OPENFILENAME ofn;

    /* _WIN32_WINNT is defined to 0x0501 */
    ofn.lStructSize         = sizeof(OPENFILENAME);
    ofn.hwndOwner           = parent;
    ofn.hInstance           = NULL;
    ofn.lpstrFilter         = filt;
    ofn.lpstrCustomFilter   = NULL;
    ofn.nFilterIndex        = 1;
    ofn.lpstrFile           = file;
    ofn.nMaxFile            = MAX_LENGTH;  /* A defined constant */
    ofn.lpstrFileTitle      = NULL;

    /* Set default folder to the PERSONAL one. */
    /* _sbuf is a global buffer declared as _TCHAR _sbuf[MAX_LENGTH] */
    if (SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, _sbuf) != 0) {
        _trace(_T("SHGetFolderPath failed."),
               _T("Cannot retrieve the personal folder."));
        return -1;
    }
    ofn.lpstrInitialDir     = _sbuf;
    ofn.lpstrTitle          = title;
    ofn.Flags               = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NONETWORKBUTTON
                              | OFN_NOREADONLYRETURN;
    if (type == OPENDLG_OPENFILE)
        ofn.Flags |= OFN_FILEMUSTEXIST;
    else if (type == OPENDLG_SAVEFILE)
        ofn.Flags |= OFN_OVERWRITEPROMPT;

    ofn.lpstrDefExt         = NULL;
    ofn.lCustData           = 0;
    ofn.pvReserved          = NULL;
    ofn.dwReserved          = 0;
    ofn.FlagsEx             = 0;

    /* Retrieve the file name. */
    if ((type == OPENDLG_OPENFILE && !GetOpenFileName(&ofn))
        || (type == OPENDLG_SAVEFILE && !GetSaveFileName(&ofn))) {
        if (CommDlgExtendedError() == 0)
            return 0;

        _tracecc(_T("GetOpenFileName or GetSaveFileName failed."),
                 _T("Cannot create Open/Save File dialog box."));

        return -2;
    }

    /* MAKEDWORD(high, low) is designed to OR (|) two WORDs to make a DWORD */
    return MAKEDWORD(ofn.nFileExtension, ofn.nFileOffset);
}