OPENFILENAME structure

This is a discussion on OPENFILENAME structure within the Windows Programming forums, part of the Platform Specific Boards category; Hi: I got a quite weird problem---> I was intializing the OPENFILENAME structure before calling GetSaveFileName(&ofn). Code: OPENFILENAME ofn; char ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    OPENFILENAME structure

    Hi:
    I got a quite weird problem--->

    I was intializing the OPENFILENAME structure before calling
    GetSaveFileName(&ofn).

    Code:
    OPENFILENAME ofn;
    char szFileName[MAX_PATH] = "Untitled";
    
    ZeroMemory(&ofn, sizeof(ofn));
    
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = hwnd;
    ofn.lpstrFile = szFileName; //set default file name
    ofn.nMaxFile = MAX_PATH; //260 Max. characters
    ........
    
    ofn.lpstrDefExt = "txt";//always add txt if no file extension added
    	ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
    Then called GetSaveFileName(&ofn) ,it was just fine, but when I changed


    Code:
    ofn.lpstrFile = szFileName;
    into:
    ofn.lpstrFile = "Untitled";
    program crashed when running it.

    I don't know what is going on? I think they are doing the same thing. Anyone knows that? Thanks.
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    lpstrFile shall point to a buffer which is to receive input.
    "Untitled" is a string constant.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. Replies: 5
    Last Post: 02-14-2006, 08:04 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 04:48 PM

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