Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error using GetOpenFileName in debug version, and not in release

Error using GetOpenFileName in debug version, and not in release

Scheduled Pinned Locked Moved C / C++ / MFC
announcementdebugginghelpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mario M 0
    wrote on last edited by
    #1

    Im trying this code in a dialog with only a button when you push it this code is executed:

    void CBorradlgDlg::OnButton1() 
    {
    	// TODO: Add your control notification handler code here
    	OPENFILENAME ofn;       // common dialog box structure
    	char szFile[512];       // buffer for file name
    	char title[]="Title openfilename";
    	// Initialize OPENFILENAME
    
    	//ZeroMemory(&ofn, sizeof(ofn));
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = GetSafeHwnd();
    	ofn.lpstrFile = szFile;
    	ofn.nMaxFile = sizeof(szFile);
    	ofn.lpstrFilter = "Object\0*.obj\0All\0*.*\0Text\0*.TXT\0";
    	ofn.nFilterIndex = 1;
    	ofn.lpstrFileTitle = NULL;
    	ofn.nMaxFileTitle = 0;
    	ofn.lpstrInitialDir = NULL;
    	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    	ofn.hInstance=0;
    	ofn.lpstrCustomFilter=NULL;
    	ofn.nMaxCustFilter=0; 
    	ofn.lpstrTitle=(LPSTR)title; 
    	ofn.nFileOffset=0; 
    	ofn.nFileExtension=0; 
    	ofn.lpstrDefExt=".obj"; 
    	ofn.lCustData=0L; 
    	ofn.lpfnHook=NULL; 
    	ofn.lpTemplateName=NULL;
    
    // Display the Open dialog box. 
    
    	if(GetOpenFileName( &ofn ) != TRUE)
    	{
    		DWORD Errval=CommDlgExtendedError();
    		switch(Errval)
    		{
    		case CDERR_DIALOGFAILURE:	AfxMessageBox("CDERR_DIALOGFAILURE "); break;
    		case CDERR_FINDRESFAILURE: AfxMessageBox("CDERR_FINDRESFAILURE "); break;
    		case CDERR_NOHINSTANCE: AfxMessageBox("CDERR_NOHINSTANCE "); break;
    		case CDERR_INITIALIZATION: AfxMessageBox("CDERR_INITIALIZATION "); break;
    		case CDERR_NOHOOK :AfxMessageBox("CDERR_NOHOOK "); break;
    		case CDERR_LOCKRESFAILURE: AfxMessageBox("CDERR_LOCKRESFAILURE "); break;
    		case CDERR_NOTEMPLATE: AfxMessageBox("CDERR_NOTEMPLATE "); break;
    		case CDERR_LOADRESFAILURE: AfxMessageBox("CDERR_LOADRESFAILURE "); break;
    		case CDERR_STRUCTSIZE: AfxMessageBox("CDERR_STRUCTSIZE "); break;
    		case CDERR_LOADSTRFAILURE: AfxMessageBox("CDERR_LOADSTRFAILURE "); break;
    		case FNERR_BUFFERTOOSMALL: AfxMessageBox("FNERR_BUFFERTOOSMALL "); break;
    		case CDERR_MEMALLOCFAILURE: AfxMessageBox("CDERR_MEMALLOCFAILURE "); break;
    		case FNERR_INVALIDFILENAME: AfxMessageBox("FNERR_INVALIDFILENAME "); break;
    		case CDERR_MEMLOCKFAILURE: AfxMessageBox("CDERR_MEMLOCKFAILURE "); break;
    		case FNERR_SUBCLASSFAILURE:AfxMessageBox("FNERR_SUBCLASSFAILURE "); break;
    		}
    	}	
    }
    

    Debug version throws CDERR_INITIALIZATION error :confused: Release version works fine :) where is the error? Im using XP VC6 SP5 Thanks.

    M 1 Reply Last reply
    0
    • M Mario M 0

      Im trying this code in a dialog with only a button when you push it this code is executed:

      void CBorradlgDlg::OnButton1() 
      {
      	// TODO: Add your control notification handler code here
      	OPENFILENAME ofn;       // common dialog box structure
      	char szFile[512];       // buffer for file name
      	char title[]="Title openfilename";
      	// Initialize OPENFILENAME
      
      	//ZeroMemory(&ofn, sizeof(ofn));
      	ofn.lStructSize = sizeof(ofn);
      	ofn.hwndOwner = GetSafeHwnd();
      	ofn.lpstrFile = szFile;
      	ofn.nMaxFile = sizeof(szFile);
      	ofn.lpstrFilter = "Object\0*.obj\0All\0*.*\0Text\0*.TXT\0";
      	ofn.nFilterIndex = 1;
      	ofn.lpstrFileTitle = NULL;
      	ofn.nMaxFileTitle = 0;
      	ofn.lpstrInitialDir = NULL;
      	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
      	ofn.hInstance=0;
      	ofn.lpstrCustomFilter=NULL;
      	ofn.nMaxCustFilter=0; 
      	ofn.lpstrTitle=(LPSTR)title; 
      	ofn.nFileOffset=0; 
      	ofn.nFileExtension=0; 
      	ofn.lpstrDefExt=".obj"; 
      	ofn.lCustData=0L; 
      	ofn.lpfnHook=NULL; 
      	ofn.lpTemplateName=NULL;
      
      // Display the Open dialog box. 
      
      	if(GetOpenFileName( &ofn ) != TRUE)
      	{
      		DWORD Errval=CommDlgExtendedError();
      		switch(Errval)
      		{
      		case CDERR_DIALOGFAILURE:	AfxMessageBox("CDERR_DIALOGFAILURE "); break;
      		case CDERR_FINDRESFAILURE: AfxMessageBox("CDERR_FINDRESFAILURE "); break;
      		case CDERR_NOHINSTANCE: AfxMessageBox("CDERR_NOHINSTANCE "); break;
      		case CDERR_INITIALIZATION: AfxMessageBox("CDERR_INITIALIZATION "); break;
      		case CDERR_NOHOOK :AfxMessageBox("CDERR_NOHOOK "); break;
      		case CDERR_LOCKRESFAILURE: AfxMessageBox("CDERR_LOCKRESFAILURE "); break;
      		case CDERR_NOTEMPLATE: AfxMessageBox("CDERR_NOTEMPLATE "); break;
      		case CDERR_LOADRESFAILURE: AfxMessageBox("CDERR_LOADRESFAILURE "); break;
      		case CDERR_STRUCTSIZE: AfxMessageBox("CDERR_STRUCTSIZE "); break;
      		case CDERR_LOADSTRFAILURE: AfxMessageBox("CDERR_LOADSTRFAILURE "); break;
      		case FNERR_BUFFERTOOSMALL: AfxMessageBox("FNERR_BUFFERTOOSMALL "); break;
      		case CDERR_MEMALLOCFAILURE: AfxMessageBox("CDERR_MEMALLOCFAILURE "); break;
      		case FNERR_INVALIDFILENAME: AfxMessageBox("FNERR_INVALIDFILENAME "); break;
      		case CDERR_MEMLOCKFAILURE: AfxMessageBox("CDERR_MEMLOCKFAILURE "); break;
      		case FNERR_SUBCLASSFAILURE:AfxMessageBox("FNERR_SUBCLASSFAILURE "); break;
      		}
      	}	
      }
      

      Debug version throws CDERR_INITIALIZATION error :confused: Release version works fine :) where is the error? Im using XP VC6 SP5 Thanks.

      M Offline
      M Offline
      Mario M 0
      wrote on last edited by
      #2

      oh my God what a silly bug :wtf: some hours later i find the solution :-D, there was an uninitialited variable

      char szFile[512]="";
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups