Why CFileDialog crashed with _WIN32_WINNT defined ahead in platform SDK 2003??

I ever used CFileDialog in a VC6 MFC application, found if define _WIN32_WINNT a new value, such as 0x500, then compiled with platform2003 SDK libraries and header files, this application will get crash after executed CFileDiag.DoModal() method, but it will ocurr in other platformSDKs, how come

ps, try my test cods if interest,

#define _WIN32_WINNT  0x0500  // defined in StdAfx.h somewhere

 CFileDialog fd(FALSE,NULL, "disk.img", OFN_HIDEREADONLY , "Storage Files (*.img)|*.img|All Files (*.*)|*.*||", NULL );
 fd.DoModal();   // <--- it will crash after a jiffy 
 



Answer this question

Why CFileDialog crashed with _WIN32_WINNT defined ahead in platform SDK 2003??

  • Ste Moore


    Thank, Ted., you are right, also help me clarified my stupid idea that each platformSDK takes a new implementation of MFC, in fact, VS takes it only.



  • techuser

    The size of the OPENFILENAME structure gets bigger when defining _WIN32_WINNT to 0x500.  This causes problems because the CFileDialog has a direct member OPENFILENAME, but MFC itself was built with the smaller size. Since the class as built in your app will not line up with what is in MFC, it crashes.

    This problem was solved fully in VC71 by changing the OPENFILENAME member of the CFileDialog class into a _declspec(property)

    For VC 6.0 the only real solution (without recompiling the MFC) is to change in
    ..\VC98\MFC\Include\AFXDLGS.H the OPENFILENAME to something like this:

    #ifdef _WIN32_WINNT>0x0400
    OPENFILENAME_NT4  m_ofn;
    #else
    OPENFILENAME  m_ofn;
    #endif


  • AnotherAlien

    The syntax that worked for me was:


    #if _WIN32_WINNT>0x0400

    OPENFILENAME_NT4 m_ofn;

    #else

    OPENFILENAME m_ofn;

    #endif



    Thank you for solving my problem!!!

  • pleenaers

    thanks - that's correct - mine was a typo.

  • Why CFileDialog crashed with _WIN32_WINNT defined ahead in platform SDK 2003??