Microsoft KB Archive/320234

= PRB: Build Errors with GDI+ and Visual C++ .NET =

Article ID: 320234

Article Last Modified on 5/4/2006

-

APPLIES TO


 * Microsoft GDI+ 1.0
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Windows XP Professional
 * Microsoft Windows XP Professional for Itanium-based systems

-



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

-or-

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.</li></ol> </li> In the StdAfx.h file, verify the following: <ul> Make sure that WIN32_LEAN_AND_MEAN is not defined.</li> Make sure that the Windows.h file is included (even for console applications).</li> Make sure that the Gdiplus.h file is included after Windows.h.</li></ul> </li>  In your .cpp file, add the follow code after the include directives: using namespace Gdiplus; </li>  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 ); </li>  In WinMain, add the following code to each exit path: GdiplusShutdown(gdiplusToken); </li> In the project settings, add the Gdiplus.lib file to the input library list.</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="references_section">