Microsoft Developer Network > Forums Home > Visual Studio Express Editions Forums > Visual C++ Express Edition > Why cant I compile a simple GDI+ example with Visual Studio 2008 Express C++?
Ask a questionAsk a question
 

AnswerWhy cant I compile a simple GDI+ example with Visual Studio 2008 Express C++?

  • Friday, October 31, 2008 4:54 PMColinGordon7860355 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    I copied the following simple GDI+ example into Visual Studio 2008 Express C++

     

    //#define UNICODE

    #include "stdafx.h"

    #include <gdiplus.h>

    using namespace Gdiplus;

    VOID OnPaint(HDC hdc)

    {

    Graphics graphics(hdc);

    Pen pen(Color(255, 0, 0, 255));

    graphics.DrawLine(&pen, 0, 0, 200, 100);

    }

    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, INT iCmdShow)

    {

    HWND hWnd;

    MSG msg;

    WNDCLASS wndClass;

    GdiplusStartupInput gdiplusStartupInput;

    ULONG_PTR gdiplusToken;

    // Initialize GDI+.

    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    wndClass.style = CS_HREDRAW | CS_VREDRAW;

    wndClass.lpfnWndProc = WndProc;

    wndClass.cbClsExtra = 0;

    wndClass.cbWndExtra = 0;

    wndClass.hInstance = hInstance;

    wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);

    wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);

    wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

    wndClass.lpszMenuName = NULL;

    wndClass.lpszClassName = TEXT("GettingStarted");

    RegisterClass(&wndClass);

    hWnd = CreateWindow(

    TEXT("GettingStarted"), // window class name

    TEXT("Getting Started"), // window caption

    WS_OVERLAPPEDWINDOW, // window style

    CW_USEDEFAULT, // initial x position

    CW_USEDEFAULT, // initial y position

    CW_USEDEFAULT, // initial x size

    CW_USEDEFAULT, // initial y size

    NULL, // parent window handle

    NULL, // window menu handle

    hInstance, // program instance handle

    NULL); // creation parameters

    ShowWindow(hWnd, iCmdShow);

    UpdateWindow(hWnd);

    while(GetMessage(&msg, NULL, 0, 0))

    {

    TranslateMessage(&msg);

    DispatchMessage(&msg);

    }

    GdiplusShutdown(gdiplusToken);

    return msg.wParam;

    } // WinMain

    LRESULT CALLBACK WndProc(HWND hWnd, UINT message,

    WPARAM wParam, LPARAM lParam)

    {

    HDC hdc;

    PAINTSTRUCT ps;

    switch(message)

    {

    case WM_PAINT:

    hdc = BeginPaint(hWnd, &ps);

    OnPaint(hdc);

    EndPaint(hWnd, &ps);

    return 0;

    case WM_DESTROY:

    PostQuitMessage(0);

    return 0;

    default:

    return DefWindowProc(hWnd, message, wParam, lParam);

    }

    } // WndProc

     

    And when I compile I get a bunch of errors starting with:

     

    1>------ Build started: Project: GDITest, Configuration: Debug Win32 ------

    1>Compiling...

    1>GDITest.cpp

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(74) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(74) : error C2440: 'initializing' : cannot convert from 'const char [37]' to 'int'

    1> There is no context in which this conversion is possible

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(74) : error C2146: syntax error : missing ';' before identifier 'IImageBytes'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(74) : error C2470: 'IImageBytes' : looks like a function definition, but there is no parameter list; skipping apparent body

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(74) : error C2059: syntax error : 'public'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(280) : error C2146: syntax error : missing ';' before identifier 'id'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(280) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusimaging.h(280) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(384) : error C2061: syntax error : identifier 'IStream'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(395) : error C2061: syntax error : identifier 'IStream'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(405) : error C2061: syntax error : identifier 'IStream'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(443) : error C2061: syntax error : identifier 'PROPID'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(444) : error C2061: syntax error : identifier 'PROPID'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(445) : error C2061: syntax error : identifier 'PROPID'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(453) : error C2061: syntax error : identifier 'PROPID'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(471) : error C2535: 'Gdiplus::Image::Image(void)' : member function already defined or declared

    1> c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(384) : see declaration of 'Gdiplus::Image::Image'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(505) : error C2061: syntax error : identifier 'IStream'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(516) : error C2061: syntax error : identifier 'IStream'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(758) : error C2061: syntax error : identifier 'IStream'

    1>c:\program files\microsoft sdks\windows\v6.0a\include\gdiplusheaders.h(813) : error C2061: syntax error : identifier 'IStream'

     

    Am I missing something really obvious here?

     

    Thanks,

     

     

     

Answers

All Replies

  • Friday, October 31, 2008 6:28 PMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Edit stdafx.h and add this line:

    #include <windows.h>
  • Tuesday, November 11, 2008 2:10 PMThe Abstraction Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    #include <objbase.h>

     

    This header is included by a lot of stuff, such as the DirectX libs, and eventually includes the necessary stuff. This should be considered a bug I think. The <gdiplus.h> lib should include it itself.

  • Tuesday, November 11, 2008 5:52 PMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    No.  Any Windows project should #include <windows.h> first.  Proper include order is important.
  • Monday, November 24, 2008 3:37 AMAaronWang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    comment this line in stdafx.h
    #define WIN32_LEAN_AND_MEAN

    will resovle this problem
  • Friday, November 06, 2009 1:10 AMMrFVD Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thx!!!

    really helpful, it happen with some many program ported to VS2008