11

When I include gdiplus.h in a program that compiles well the first(there are many) error I get is:

c:\program files (x86)\microsoft sdks\windows\v7.0a\include\GdiplusImaging.h(77): error C2504: 'IUnknown' : base class undefined

Part of GdiplusImaging.h:

IImageBytes : public IUnknown  <<< error!
{
public:
     ...

Why it is so? Where is this IUnknown class? And why it's not in GdiplusImaging.h?

My system is Windows7 x64. VisualStudio 2010.

Including part:

#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib, "gdiplus.lib")
Sergey
  • 19,487
  • 13
  • 44
  • 68

2 Answers2

35

These are the standard includes for using GDI+:

#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
SChepurin
  • 1,814
  • 25
  • 17
  • I used this exact block, but still had issues with min/max macros being undefined in gdiplustype.h file (that is included internally by gdiplus.h). Following thread helped -http://stackoverflow.com/questions/4913922/possible-problems-with-nominmax-on-visual-c – Aditya Kumar Pandey Jun 15 '15 at 13:48
  • This doesn't work under VS2017 if you try to build it for platform toolset as `Visual Studio 2017 - Windows XP (v141_xp)`. Here's [more info](https://stackoverflow.com/questions/57014731/gdi-library-causes-error-c2760-syntax-error-unexpected-token-identifier-e). Did anyone figure out how to build these GDI+ libraries? – c00000fd Jul 13 '19 at 17:29
7

You should try to add windows.h and Unknwn.h header before gdiplus.h

#include <Unknwn.h>
#include <windows.h>
#include <gdiplus.h>
evandrix
  • 6,041
  • 4
  • 27
  • 38
Cedekasme
  • 2,027
  • 1
  • 16
  • 16