Porting MFC projects to Visual C++ .NET or to Visual C++ 2005 changes in the target operating system (320479)
The information in this article applies to:
- Microsoft Visual C++ 2005 Express Edition
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
This article was previously published under Q320479 SYMPTOMS
When you port a Microsoft Foundation Classes (MFC) project that was created by using Microsoft Visual C++ 6.0 to Microsoft Visual C++ .NET or to Microsoft Visual C++ 2005 and then you rebuild the project in Microsoft Visual Studio .NET, the new binaries fail in different ways when you run the project on Microsoft Windows NT 4.0. When you build the project in Visual C++ 6.0, the same source files build binaries that run without error on Windows NT.
CAUSE
Code generated by wizards in previous versions of Visual C++ did not define a value for _WIN32_WINNT in Stdafx.h. New MFC projects in Visual Studio .NET explicitly define _WIN32_WINNT to the standard 0x0400 setting, which targets the Windows NT 4.0 and later operating systems.
Conversion does not change the source files, but the new project uses the new MFC header files for Visual C++ .NET or for Visual C++ 2005. If _WIN32_WINNT was not explicitly defined in the older Stdafx.h files, the included MFC headers define _WIN32_WINNT for you.
The statement
#include <afxwin.h>
eventually includes Afxv_w32.h. This header defines _WIN32_WINNT (if it is not already defined) to be equal to WINVER. In Visual C++ .NET or in Visual C++ 2005, WINVER is set explicitly in Windows.h to be 0x0501. This setting targets the Microsoft Windows 2000 operating system and Microsoft Windows XP operating system, and creates structure definitions that Windows NT 4.0 and earlier do not recognize.
RESOLUTION
To resolve this problem, add at least the following line of code at the beginning of the Stdafx.h file in the converted project:
#define _WIN32_WINNT 0x0400
Verify that this code is added before any MFC header files are included.
For a more complete solution, create a new default MFC project in your version of Visual C++ .NET or of Visual C++ 2005, and then paste the Stdafx.h code created by Visual C++ .NET or by Visual C++ 2005 in the default project before the following line of code:
#include <afxwin.h>
This resolution may help you to work around other issues. The following code was created by the most current version of Visual C++ .NET or of Visual C++ 2005 as of this writing:
// Stdafx.h : Include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently.
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used items from Windows headers.
#endif
// Modify the following defines if you have to target an OS before the ones
// specified in the following code. See MSDN for the latest information
// about corresponding values for different operating systems.
#ifndef WINVER // Permit use of features specific to Windows 95 and Windows NT 4.0 or later.
#define WINVER 0x0400 // Change this to the appropriate value to target
#endif // Windows 98 and Windows 2000 or later.
#ifndef _WIN32_WINNT // Permit use of features specific to Windows NT 4.0 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target
#endif // Windows 98 and Windows 2000 or later.
#ifndef _WIN32_WINDOWS // Permit use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target
#endif // Windows Millennium Edition or later.
#ifndef _WIN32_IE // Permit use of features specific to Internet Explorer 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target
#endif // Internet Explorer 5.0 or later.
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // Some CString constructors will be explicit.
// Turns off MFC feature that hides of some common warning messages
// that are frequently and safely ignored .
#define _AFX_ALL_WARNINGS
REFERENCES
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
Modification Type: | Major | Last Reviewed: | 1/17/2006 |
---|
Keywords: | kbmigrate kbprb KB320479 kbAudDeveloper |
---|
|