Search

#include <afxcontrolbars.h> is not compatible with #define NOMINMAX by BongoVR

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 622942
Opened: 11/18/2010 7:05:44 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
When defining
#define NOMINMAX
in stdafx.h it is not possible to include afxcontrolbars.h due to several uses of the min and max macros.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

put the following sequence in stdafx.h:

#define NOMINMAX
#include <afx.h>
#include <afxwin.h>
#include <afxmt.h>
#include <afxdb.h>
#include <shlobj.h>
#include <afxcontrolbars.h>

Product Language

German

Operating System

Windows XP

Operating System Language

German

Actual results

error C3861 obtained for "min" and "max" in A LOT OF header files implicitly included by afxcontrolbars.h

Most errors can be avoided using the following:
#include <algorithm>
namespace Gdiplus
{
    using std::min;
    using std::max;
}
right before the include.

But the errors in
vs 10\vc\atlmfc\include\afxtoolbar.h(171)
vs 10\vc\atlmfc\include\afxmenubar.h(160)
vs 10\vc\atlmfc\include\afxdesktopalertwnd.h(81)
still remain.

Expected results

clean complie
File Attachments
File Name Submitted By Submitted On File Size  
Test2010.zip 11/18/2010 1.83 MB
afxcontrolbars.zip 11/18/2010 1 KB
Sign in to post a comment.
Posted by Microsoft on 12/2/2010 at 9:16 AM
Hello,

Thanks for the feedback. This issue has been fixed in MFC for the next major release of Visual Studio. The implementation of the methods has been moved from the header files into the respective implementation files, per your suggestion.

Pat Brenner
Visual C++ Libraries Development
Posted by BongoVR on 11/29/2010 at 11:14 PM
Hello,

thanks for sharing your ideas.

Unfortunately, this does not help. std::min is a template assuming that its two arguments are of the same type. On the other hand, the min macro does not care about argument types as long as the operators work; and they do for e. g. int/UINT etc.

I tried using such a workaround before, and this required me to adjust the types in the header code or to explcitly resolve ambiguities, like changing to min<int>(...
This does more harm than it serves.
I can understand that the MFC headers are not supposed to define the min/max macros again and again. So, a better resolution would be to remove the code using these macros from the header altogether and put it into the respective implementation files. As far as I remember, most of these statements occur in virtual functions. To some people, declaring virtual functions inline is a questionable practice anyway.
How about considering this change for the next MFC version?
Posted by Microsoft on 11/29/2010 at 12:35 PM
Hello,

Thanks for the report. This issue is by design in MFC. MFC requires definitions of min and max. Certainly there is no reason to duplicate the macro definitions in the MFC headers, since the same definitions can be obtained by simply not defining NOMINMAX.

If you wish to build your MFC project with NOMINMAX set, you can instead use the following workaround in your stdafx.h file:

#define NOMINMAX
#include <algorithm>
using std::min;
using std::max;

This will provide alternate definitions so that your project will build successfully. I hope this helps.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft on 11/22/2010 at 12:36 AM
Thanks for your feedback.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by BongoVR on 11/18/2010 at 10:58 PM
The attached afxcontrolbars.zip contains a patched afxcontrolbars.h header file which corrects this issue.
Posted by BongoVR on 11/18/2010 at 10:55 PM
The attached project in Test2010.zip shows this problem.
Posted by Microsoft on 11/18/2010 at 9:18 PM
Thank you for reporting this issue. Unfortunately, we are unable to reproduce the issue with the steps you provided.

Could you please provide us with a sample project?

It would be greatly appreciated if you could provide us this information as quickly as possible.

Thank you,
Posted by Microsoft on 11/18/2010 at 7:22 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.