GetSaveFileName

This is a discussion on GetSaveFileName within the Windows Programming forums, part of the Platform Specific Boards category; Ok, I dont understand why this doenst work. I have a buffer, szFile which holds the file name. and pass ...

  1. #1
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    GetSaveFileName

    Ok, I dont understand why this doenst work. I have a buffer, szFile which holds the file name. and pass that to my OPENFILENAME struct. The dialog opens when I call GetSaveFileName and shows the desired name, but if i change the name of the file and press save and try to access the lpstrFile after the call to GetSaveFIleName the program causes an error.

    Code:
    static ::OPENFILENAME ofn;
    	static char szFilter[] = "Text Files (*.TXT)\0*.txt\0";
    
         ofn.lStructSize       = sizeof (OPENFILENAME) ;
         ofn.hwndOwner         = hWnd ;
         ofn.hInstance         = NULL ;
         ofn.lpstrFilter       = szFilter ;
         ofn.lpstrCustomFilter = NULL ;
         ofn.nMaxCustFilter    = 0 ;
         ofn.nFilterIndex      = 0 ;
         ofn.lpstrFile         = NULL ;        
         ofn.nMaxFile          = _MAX_PATH ;
         ofn.lpstrFileTitle    = NULL ;       
         ofn.nMaxFileTitle     = _MAX_FNAME + _MAX_EXT ;
         ofn.lpstrInitialDir   = NULL ;
    	 ofn.lpstrTitle        = "Save Output As:" ;
         ofn.Flags             = 0 ;             
         ofn.nFileOffset       = 0 ;
         ofn.nFileExtension    = 0 ;
         ofn.lpstrDefExt       = "txt" ;
         ofn.lCustData         = 0L ;
         ofn.lpfnHook          = NULL ;
         
         char szFile[] = "Output.txt";
         ofn.lpstrFile = szFile;
         ofstream out;
        if(GetSaveFileName(&ofn))
        {    if(strcmp(szFile,ofn.lpstrFile)) // this fails even if i select output.txt as name bc lpstrFile is null now?
               {    out.open(szFile,ios::out);
                     ....
               }
               else   
               {   out.open(ofn.lpstrFile,ios::out); // this causes prog to crash
                    .....
                }
           }

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Did you try using a message box to debug? Have the text outputted to a message box and see exactly what is in there.

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Did that. Its all garbage after the call to GetSaveFileName

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Didnt change anything, and no it works all magically by itself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doesn't write in file when call GetSaveFileName()
    By randall81 in forum Windows Programming
    Replies: 1
    Last Post: 03-28-2009, 02:34 PM
  2. GetSaveFileName exception
    By stanlvw in forum Windows Programming
    Replies: 4
    Last Post: 07-04-2008, 12:42 PM
  3. Major Problems with GetSaveFileName() and GetOpenFileName()
    By CodeHacker in forum Windows Programming
    Replies: 8
    Last Post: 07-12-2004, 12:05 PM
  4. CFileDialog or GetSaveFileName()
    By jkw2068 in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2003, 10:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21