In order to access Win2000 specific APIs etc, one needs the following #define in
the application's stdafx.h (before any other #includes)
#define _WIN32_WINNT 0x0500
With the latest platform SDK, this also has the side effect of changing the
definition for the OPENFILENAME struct; in particular it makes it larger. This
is because of the following lines in the "CommDlg.h"
typedef struct tagOFNA {
DWORD lStructSize;
...
...
LPCSTR lpTemplateName;
#ifdef _MAC
LPEDITMENU lpEditInfo;
LPCSTR lpstrPrompt;
#endif
#if (_WIN32_WINNT >= 0x0500)
void * pvReserved;
DWORD dwReserved;
DWORD FlagsEx;
#endif
} OPENFILENAMEA, *LPOPENFILENAMEA;
This means when the definition of class CFileDialog
is compiled, it's m_ofn
member will have a different size than in the MFC dlls. This is because
CFileDialog
is defined as:
class CFileDialog : public CCommonDialog
{
DECLARE_DYNAMIC(CFileDialog)
public:
OPENFILENAME m_ofn;
...
...
};
When a CFileDialog
is used in your code and is destructed, the wrong offsets
into memory for member varialbes will be unsed, and in particular, the
m_strFilter will not destruct properly.
The work-around for this is to #undef _WIN32_WINNT before the #include
<afxext.h> in the application's stdafx.h:
#define _WIN32_WINNT 0x0500
#define VC_EXTRALEAN
#include <afxwin.h> // MFC core and standard components
#undef _WIN32_WINNT
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif
Now, <afxext.h> will (indrectly) #include <CommDlg.h>
and define CFileDIalog
all
without the offending _WIN32_WINNT
.
NOTE: This only works because the VC_EXTRALEAN
stops <afxwin.h> from including
CommDlg.h earlier.