#include causes error

2020-07-06 07:06发布

问题:

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")

回答1:

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")


回答2:

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

#include <Unknwn.h>    
#include <windows.h>
#include <gdiplus.h>