Solved

FYI: MFC BUG with Win2000 and Platform SDK

Posted on 2000-02-23
1
599 Views
Last Modified: 2013-11-20
[Any comments on this from other Experts]

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 // (_WIN32_WINNT >= 0x0500)
     } 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:
     // Attributes
>>>       OPENFILENAME m_ofn; // open file parameter block
...
...
     };

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   /* allow Win2000 specific calls */
     #define VC_EXTRALEAN          // Exclude rarely-used stuff from Windows
headers
     #include <afxwin.h>         // MFC core and standard components
>>>  #undef _WIN32_WINNT           /* allow CFileDialog to build with the
correct size */
     #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 // _AFX_NO_AFXCMN_SUPPORT

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.

0
Comment
Question by:RONSLOW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
darinw earned 0 total points
ID: 2610632
Posting answer to save information to PAQ.

darinw
Customer Service
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven archtype selection in eclipse 1 59
has77  challenge 9 104
I could not set window to top 4 62
Problem to Office 1 67
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question