CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2001
    Location
    Singapore
    Posts
    2

    NT/2000 - Open / Save File Dialog causes application to exit

    Hi,

    On WinNT and 2000, GetSaveFileName causes my application to exit without any error message. The application just closes abruptly. Works fine on Win95. Any idea what can be the problem?


    GetSaveFileName(&ofn);




    Thanks in advance.


  2. #2
    Join Date
    Aug 2001
    Posts
    1

    Re: NT/2000 - Open / Save File Dialog causes application to exit

    I am having the same problem and getting quite nuts. It only happens when I run the program from the compiler itself. Ran by itself it works fine. Anyone else having this problem?

    Paul Paschievici.


  3. #3
    Join Date
    Oct 2001
    Posts
    1

    Re: NT/2000 - Open / Save File Dialog causes application to exit

    I'm not sure if the problem that I encountered is related or not, but when I ran GetOpenFileName/GetSaveFileName it corrupted the stack. Calling those functions didn't cause the crash, but returning from the function that called them crashed. I fixed it by making sure that I defined everything in the OPENFILENAME structure even if it was just setting it to NULL.

    Hope that helps.

    Brock Atchison


  4. #4
    Join Date
    Mar 2004
    Posts
    9

    Re: NT/2000 - Open / Save File Dialog causes application to exit

    My OS is WinXP Pro(sp2). If I run my program compilied with MSVC 6.0 it works great, the same program compilied with MSVC 8.0 closes the main window and exits. No errors or Send crash to Microsoft. Here is the code:
    Code:
    //////////////////////////////////////////////////////////////////////////////
    // prompt for file name - used for open and save as
    // static function called from app
    BOOL PromptForFileName(CString& fileName, BOOL bOpenFileDialog)
    {
    	// TODO: Add your control notification handler code here
    	CString szFilter = "Windows Bitmap Files (*.BMP; *.DIB) |*.BMP; *.DIB||";
    	LPSTR title;
    	char szFile[MAX_PATH];
    	szFile[0] = '\0'; 
    	if (bOpenFileDialog) title="Open image file"; else title="Save image file";
    	OPENFILENAME ofn;
    	ZeroMemory(&ofn, sizeof(OPENFILENAME));
    	ofn.lStructSize = sizeof(OPENFILENAME);
    	ofn.hwndOwner = g_hWnd;
    	ofn.hInstance = hInst;
    	ofn.lpstrFile = szFile;
    	ofn.nMaxFile = MAX_PATH;
    	ofn.lpstrFilter = szFilter;
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFileTitle = title;
    	ofn.nMaxFileTitle = MAX_PATH;
    	ofn.lpstrDefExt = _T("bmp");
    	ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_ENABLEHOOK;
    	ofn.lpfnHook = OFNHookProc;
    
    	if (GetSaveFileName(&ofn))
    	{
    		m_strPathName = ofn.lpstrFile;
    	}
    	else
    	{
    		DWORD dwError = ::CommDlgExtendedError();
    		CString szError;
    		szError.Format("Open File Dialog Failed, GetFileName returned: %ld", dwError);
    #if _MSC_VER < 1400
    		strcpy(info.szLastError, szError);
    #else
    		strcpy_s(info.szLastError, 256, szError);
    #endif
    		return FALSE;
    	}
    	return TRUE;
    }
    //////////////////////////////////////////////////////////////////////////////
    UINT_PTR CALLBACK OFNHookProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(uiMsg)
    	{
    	case WM_INITDIALOG:
    		CenterWindow(hwnd);
    		return 0;
    	}
    	return 0;
    }

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: NT/2000 - Open / Save File Dialog causes application to exit

    Quote Originally Posted by Roger65
    My OS is WinXP Pro(sp2). If I run my program compilied with MSVC 6.0 it works great, the same program compilied with MSVC 8.0 closes the main window and exits. No errors or Send crash to Microsoft.
    Well...did you run it under the debugger?

  6. #6
    Join Date
    Mar 2004
    Posts
    9

    Re: NT/2000 - Open / Save File Dialog causes application to exit

    In debug mode you can't open the dialog box, get access error.

  7. #7
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: NT/2000 - Open / Save File Dialog causes application to exit

    Quote Originally Posted by Roger65
    In debug mode you can't open the dialog box, get access error.
    Yes....but this is exactly what you want...at that time, you are brought back to the debugger and can then take a look at the callstack etc. to find out what causes the problem...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured