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

-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:
  1. 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.
  2. 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.
  3. Follow these steps to create a new Visual C++ Win32 project:
    1. Start Visual Studio .NET.
    2. On the File menu, point to New, and then click Project.
    3. Click Visual C++ Projects under Project Types, and then click Win32 Project under Templates.
  4. 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.
  5. In your .cpp file, add the follow code after the include directives:
    using namespace Gdiplus;
    					
  6. 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 );
    					
  7. In WinMain, add the following code to each exit path:
    GdiplusShutdown(gdiplusToken);
    					
  8. In the project settings, add the Gdiplus.lib file to the input library list.

STATUS

This behavior is by design.

REFERENCES

For 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:MinorLast Reviewed:5/4/2006
Keywords:kbDSWGDI2003Swept kbprb KB320234 kbAudDeveloper