PRB: Build Errors with GDI+ and Visual C++ .NET (320234)
The information in this article applies to:
- Microsoft GDI+ 1.0
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++ .NET (2003)
- Microsoft Windows XP Professional
- the operating system: Microsoft Windows XP 64-Bit Edition
This article was previously published under Q320234 SYMPTOMS If you do not configure GDI+ and the Visual C++ .NET
project that uses GDI+ correctly, you may receive error messages when you build
the project. Some of the more common error messages include the following:
error C2065: 'ULONG_PTR' : undeclared identifier
error C2501: 'MIDL_INTERFACE' : missing
storage-class or type specifiers CAUSE The GDI+ 1.0 Software Development Kit (SDK) requires the
current Microsoft Platform SDK header and library files. Also, projects that
use GDI+ must have certain settings to build successfully.
For
example, the c2065 error occurs when you use GDI+ headers with older Platform
SDK installations. Also, GDI+ relies on type definitions that are located in
the Windows.h file when WIN32_LEAN_AND_MEAN is not defined. The c2501 error
occurs if you include GDI+ when WIN32_LEAN_AND_MEAN is defined. RESOLUTION To successfully build a Visual C++ .NET project that uses
GDI+, follow these steps:
- Make sure that the current Platform SDK is installed. The
current Platform SDK is the version of the Platform SDK from which your GDI+
headers and libraries are taken.
- Make sure that your installation of Microsoft Visual Studio
.NET is configured to read from the Platform SDK include directories and
library directories before it reads from its own directories.
- Follow these steps to create a new Visual C++ Win32
project:
- Start Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- Click Visual C++ Projects under Project Types, and then click Win32 Project under Templates.
- In the StdAfx.h file, verify the following:
- Make sure that WIN32_LEAN_AND_MEAN is not
defined.
- Make sure that the Windows.h file is included (even for
console applications).
- Make sure that the Gdiplus.h file is included after
Windows.h.
- In your .cpp file, add the follow code after the include
directives:
using namespace Gdiplus;
- In WinMain, make sure that the following code is one of the
first items to be executed:
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup( &gdiplusToken, &gdiplusStartupInput, NULL );
- In WinMain, add the following code to each exit path:
GdiplusShutdown(gdiplusToken);
- In the project settings, add the Gdiplus.lib file to the
input library list.
STATUSThis
behavior is by design.REFERENCESFor
additional information about a project that uses both MFC and GDI+, click the
article number below to view the article in the Microsoft Knowledge Base: 317799 PRB: Microsoft Foundation Classes DEBUG_NEW Does Not Work with GDI+
Modification Type: | Minor | Last Reviewed: | 5/4/2006 |
---|
Keywords: | kbDSWGDI2003Swept kbprb KB320234 kbAudDeveloper |
---|
|