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. CFileDialog crashes in Platform SDK

CFileDialog crashes in Platform SDK

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiosysadminwindows-adminhelpquestion
4 Posts 3 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
    Marius Bancila
    wrote on last edited by
    #1

    I have installed Platform SDK Windows Server 2003 (I work in VS 6.0 on WinXP) and I have a problem with CFileDialog. This code void CFileTestView::OnViewFile() { CFileDialog dlg(TRUE); dlg.DoModal(); } worked just fine before defining _WIN32_WINNT, which I need to use different functions and constants. Now, when I define it #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0501 // can be 0x0500 as well #endif my code just crashes in ~CFileDialog (when dlg does out of scope and is destroyed). Since m_ofn member of CFileDialog depends on this _WIN32_WINT: typedef struct tagOFN { // ... #if (_WIN32_WINNT >= 0x0500) void * pvReserved; DWORD dwReserved; DWORD FlagsEx; #endif // (_WIN32_WINNT >= 0x0500) } OPENFILENAME I rewrote the code this way: void CFileTestView::OnViewFile() { CFileDialog dlg(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif dlg.DoModal(); // can also miss } but I still get a first-chance exception in FileTest.Exe (KERNEL32.dll) 0xC0000005: Access Violation (the usual stuff). Now, I found out that if I declare dlg dinamically it doesn't crash: void CFileTestView::OnViewFile() { CFileDialog* dlg = new CFileDialog*(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif delete dlg; // OK } But If I derive CFileDialog to CMyFileDialog the program still crashes at delete: void CFileTestView::OnViewFile() { CMyFileDialog* dlg = new CMyFileDialog*(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif delete dlg; // crash boom boom } Any ideas? Thanks!

    D B 2 Replies Last reply
    0
    • M Marius Bancila

      I have installed Platform SDK Windows Server 2003 (I work in VS 6.0 on WinXP) and I have a problem with CFileDialog. This code void CFileTestView::OnViewFile() { CFileDialog dlg(TRUE); dlg.DoModal(); } worked just fine before defining _WIN32_WINNT, which I need to use different functions and constants. Now, when I define it #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0501 // can be 0x0500 as well #endif my code just crashes in ~CFileDialog (when dlg does out of scope and is destroyed). Since m_ofn member of CFileDialog depends on this _WIN32_WINT: typedef struct tagOFN { // ... #if (_WIN32_WINNT >= 0x0500) void * pvReserved; DWORD dwReserved; DWORD FlagsEx; #endif // (_WIN32_WINNT >= 0x0500) } OPENFILENAME I rewrote the code this way: void CFileTestView::OnViewFile() { CFileDialog dlg(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif dlg.DoModal(); // can also miss } but I still get a first-chance exception in FileTest.Exe (KERNEL32.dll) 0xC0000005: Access Violation (the usual stuff). Now, I found out that if I declare dlg dinamically it doesn't crash: void CFileTestView::OnViewFile() { CFileDialog* dlg = new CFileDialog*(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif delete dlg; // OK } But If I derive CFileDialog to CMyFileDialog the program still crashes at delete: void CFileTestView::OnViewFile() { CMyFileDialog* dlg = new CMyFileDialog*(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif delete dlg; // crash boom boom } Any ideas? Thanks!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Does the problem persist if you use GetOpenFileName() instead?


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      1 Reply Last reply
      0
      • M Marius Bancila

        I have installed Platform SDK Windows Server 2003 (I work in VS 6.0 on WinXP) and I have a problem with CFileDialog. This code void CFileTestView::OnViewFile() { CFileDialog dlg(TRUE); dlg.DoModal(); } worked just fine before defining _WIN32_WINNT, which I need to use different functions and constants. Now, when I define it #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0501 // can be 0x0500 as well #endif my code just crashes in ~CFileDialog (when dlg does out of scope and is destroyed). Since m_ofn member of CFileDialog depends on this _WIN32_WINT: typedef struct tagOFN { // ... #if (_WIN32_WINNT >= 0x0500) void * pvReserved; DWORD dwReserved; DWORD FlagsEx; #endif // (_WIN32_WINNT >= 0x0500) } OPENFILENAME I rewrote the code this way: void CFileTestView::OnViewFile() { CFileDialog dlg(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif dlg.DoModal(); // can also miss } but I still get a first-chance exception in FileTest.Exe (KERNEL32.dll) 0xC0000005: Access Violation (the usual stuff). Now, I found out that if I declare dlg dinamically it doesn't crash: void CFileTestView::OnViewFile() { CFileDialog* dlg = new CFileDialog*(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif delete dlg; // OK } But If I derive CFileDialog to CMyFileDialog the program still crashes at delete: void CFileTestView::OnViewFile() { CMyFileDialog* dlg = new CMyFileDialog*(TRUE); dlg.m_ofn.lStructSize = sizeof(OPENFILENAME); // 88 bytes #if (_WIN32_WINNT >= 0x0500) dlg.m_ofn.pvReserved = NULL; dlg.m_ofn.dwReserved = 0; dlg.m_ofn.FlagsEx = 0; #endif delete dlg; // crash boom boom } Any ideas? Thanks!

        B Offline
        B Offline
        Blake Miller
        wrote on last edited by
        #3

        Here's an idea... Look at the beginning of the class definition for CFileDialog... class CFileDialog : public CCommonDialog { DECLARE_DYNAMIC(CFileDialog) public: // Attributes OPENFILENAME m_ofn; // open file parameter block Whoa! There's an OPENFILENAME m_ofn member variable, and YOU DO NOT CONTROL IT'S SIZE! You would have to rebuild your MFC DLL or rebuild the static MFC library to which you are linking, using the NEW size. Anyway, that is why you get the crash - you write to data that overwrites something else! If you really need these new fields, you are going to have to 'swipe' the CFileDialog source code and make your own using the new data structure. Otherwise, just use OpenFileName as David Crow suggests.

        M 1 Reply Last reply
        0
        • B Blake Miller

          Here's an idea... Look at the beginning of the class definition for CFileDialog... class CFileDialog : public CCommonDialog { DECLARE_DYNAMIC(CFileDialog) public: // Attributes OPENFILENAME m_ofn; // open file parameter block Whoa! There's an OPENFILENAME m_ofn member variable, and YOU DO NOT CONTROL IT'S SIZE! You would have to rebuild your MFC DLL or rebuild the static MFC library to which you are linking, using the NEW size. Anyway, that is why you get the crash - you write to data that overwrites something else! If you really need these new fields, you are going to have to 'swipe' the CFileDialog source code and make your own using the new data structure. Otherwise, just use OpenFileName as David Crow suggests.

          M Offline
          M Offline
          Marius Bancila
          wrote on last edited by
          #4

          First, my project is too large and I don't want to go and replace everything with OpenFileName(). Second, when I have to define _WIN32_WINNT to 0x0501 because I need it to use other functions that are define like #if (_WIN32_WINNT >= 0x0500) //here is the function #endif so OPENFILENAME will have the extra three data members. If Platform SDK provides me this (actually) new structure doesn't it also provide the necessary lib? Because of my settings it should try to link first to SDK libs and only after (if not found) to VS6.0 old libs.

          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