免责声明:我只是开始使用C语言,所以很可能我遗漏了一些明显的东西,或者没有考虑正确的方法! :)
我将如何在纯C语言中使用GDI +?
据我了解,GDI +已经包装了为C++创建的对象,但是在它的下面是一个平面API,可通过C友好 header gdiplusflat.h
访问该API。
我的问题是,当我#include它时,出现以下错误:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gdiplusflat.h(30) : error C2143: syntax error : missing '{' before '__stdcall'
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gdiplusflat.h(31) : error C2146: syntax error : missing ')' before identifier 'brushMode'
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gdiplusflat.h(31) : error C2061: syntax error : identifier 'brushMode'
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gdiplusflat.h(31) : error C2059: syntax error : ';'
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gdiplusflat.h(31) : error C2059: syntax error : ','
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\gdiplusflat.h(31) : error C2059: syntax error : ')'
and 100 more...
现在,我认为这些错误是由于未定义
GpStatus
所致,因为窥探GdiPlusFlat.h
显示所有功能均具有以下风格:// WINGDIAPI is #defined as __stdcall
GpStatus WINGDIPAPI
GdipCreatePath(GpFillMode brushMode, GpPath **path);
GpStatus WINGDIPAPI
GdipCreatePath2(GDIPCONST GpPointF*, GDIPCONST BYTE*, INT, GpFillMode,
GpPath **path);
GpStatus WINGDIPAPI
GdipCreatePath2I(GDIPCONST GpPoint*, GDIPCONST BYTE*, INT, GpFillMode,
GpPath **path);
etc...
问题在于
GpStatus
是Status
(C++头)中GdiPlusGpStubs.h
的类型定义,而Status
本身是GdiPlusTypes.h
(也是C++头)中定义的枚举。我尝试自己定义枚举,但是由于某种原因,编译器不会接受它!那么...如何在C语言中精确使用GDI +函数呢?我应该只是动态加载gdiplus.dll吗?
最佳答案
问题在于,gdiplusflat.h确实需要包含更多的gdi * .h头文件。但是,这些头文件中有许多具有gdiplusflat.h引用的必需typedef声明的文件,也包含“类”声明和其他C++关键字。当看到这些行时,C编译器将出错。
您有两种选择。
X
enum Status
{
Ok = 0,
GenericError = 1,
InvalidParameter = 2,
OutOfMemory = 3,
ObjectBusy = 4,
InsufficientBuffer = 5,
NotImplemented = 6,
Win32Error = 7,
WrongState = 8,
Aborted = 9,
FileNotFound = 10,
ValueOverflow = 11,
AccessDenied = 12,
UnknownImageFormat = 13,
FontFamilyNotFound = 14,
FontStyleNotFound = 15,
NotTrueTypeFont = 16,
UnsupportedGdiplusVersion = 17,
GdiplusNotInitialized = 18,
PropertyNotFound = 19,
PropertyNotSupported = 20,
#if (GDIPVER >= 0x0110)
ProfileNotFound = 21,
#endif //(GDIPVER >= 0x0110)
};
typedef Status GpStatus;
enum FillMode
{
FillModeAlternate, // 0
FillModeWinding // 1
};
typedef FillMode GpFillMode;
struct GpPath {};
typedef float REAL;
struct GpPointF
{
REAL x;
REAL y;
};
struct GpPoint
{
int x;
int y;
};
#include <gdiplusflat.h>
关于c - 如何在C语言中使用GDI +?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5114591/