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. GetOpenFileName unhandled exception.

GetOpenFileName unhandled exception.

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 2 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.
  • R Offline
    R Offline
    redeemer
    wrote on last edited by
    #1

    here's the code, when i get to the GetOpenFileName line it gives me an unhandled exception, i can't figure out what's wrong, here's the code:

    void OnBrowse()
    {
    OPENFILENAME ofn;
    char szFileName[MAX_PATH+1];
    const char szFilter[] = "All Files (*.*)\0" "*.*\0";

    szFileName\[0\] = '\\0';
    ofn.lStructSize = sizeof(OPENFILENAME);
    
    ofn.hwndOwner = ghWnd;
    ofn.lpstrFilter = szFilter;
    ofn.lpstrCustomFilter = (LPSTR)NULL;
    ofn.nFilterIndex = 1;
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = sizeof(szFileName);
    ofn.lpstrFileTitle = NULL;
    ofn.lpstrTitle = (LPSTR)NULL;
    ofn.Flags = OFN\_ENABLESIZING | OFN\_FILEMUSTEXIST | OFN\_HIDEREADONLY | OFN\_PATHMUSTEXIST | OFN\_EXPLORER;
    ofn.nFileOffset = 0;
    ofn.nFileExtension = 0;
    ofn.lpstrDefExt = "txt";
    
    
    if (GetOpenFileName(&ofn))
    	SetDlgItemText(ghWnd, IDC\_LIST, szFileName);
    

    }

    Thanks in advance. -Rune Svendsen

    M 1 Reply Last reply
    0
    • R redeemer

      here's the code, when i get to the GetOpenFileName line it gives me an unhandled exception, i can't figure out what's wrong, here's the code:

      void OnBrowse()
      {
      OPENFILENAME ofn;
      char szFileName[MAX_PATH+1];
      const char szFilter[] = "All Files (*.*)\0" "*.*\0";

      szFileName\[0\] = '\\0';
      ofn.lStructSize = sizeof(OPENFILENAME);
      
      ofn.hwndOwner = ghWnd;
      ofn.lpstrFilter = szFilter;
      ofn.lpstrCustomFilter = (LPSTR)NULL;
      ofn.nFilterIndex = 1;
      ofn.lpstrFile = szFileName;
      ofn.nMaxFile = sizeof(szFileName);
      ofn.lpstrFileTitle = NULL;
      ofn.lpstrTitle = (LPSTR)NULL;
      ofn.Flags = OFN\_ENABLESIZING | OFN\_FILEMUSTEXIST | OFN\_HIDEREADONLY | OFN\_PATHMUSTEXIST | OFN\_EXPLORER;
      ofn.nFileOffset = 0;
      ofn.nFileExtension = 0;
      ofn.lpstrDefExt = "txt";
      
      
      if (GetOpenFileName(&ofn))
      	SetDlgItemText(ghWnd, IDC\_LIST, szFileName);
      

      }

      Thanks in advance. -Rune Svendsen

      M Offline
      M Offline
      Mike Upton
      wrote on last edited by
      #2

      A couple of points I can see from looking at the documentation for GetOpenFileName().

      • What operating system are you using? There's a note in the platform SDK documentation that says: "lStructSize Specifies the length, in bytes, of the structure. Windows NT 4.0: In an application that is compiled with WINVER and _WIN32_WINNT >= 0x0500, use OPENFILENAME_SIZE_VERSION_400 for this member. Windows 2000/XP: Use sizeof (OPENFILENAME) for this parameter."
      • This is more likely to be the problem - you've forgotten lpstrInitialDir. It should either be the directory you want the dialog to start in, or NULL.

      Hope that helps!


      "We are the knights who say Ni" (The Knights Who Say Ni)

      R 1 Reply Last reply
      0
      • M Mike Upton

        A couple of points I can see from looking at the documentation for GetOpenFileName().

        • What operating system are you using? There's a note in the platform SDK documentation that says: "lStructSize Specifies the length, in bytes, of the structure. Windows NT 4.0: In an application that is compiled with WINVER and _WIN32_WINNT >= 0x0500, use OPENFILENAME_SIZE_VERSION_400 for this member. Windows 2000/XP: Use sizeof (OPENFILENAME) for this parameter."
        • This is more likely to be the problem - you've forgotten lpstrInitialDir. It should either be the directory you want the dialog to start in, or NULL.

        Hope that helps!


        "We are the knights who say Ni" (The Knights Who Say Ni)

        R Offline
        R Offline
        redeemer
        wrote on last edited by
        #3

        Thanks, it was the lpstrInitialDir.

        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