今天用IMageEx来向窗口显示动画,用到了GDI+;结果遇到了
error C2660: “Gdiplus::GdiplusBase::operator new”: 函数不接受 3 个参数 这个编译错误!
上网查了看一个网友说的是:
找到解决方案,原来是微软的 DEBUG_NEW 和 GDI+ 不匹配造成的。
完整的解决方案地址:http://support.microsoft.com/kb/317799/
这里贴出官方文档:
(1)原因:
在调试版本中 MFC 定义扩展到带有两个额外的参数的重载 新 运算符的 new 运算符的预处理器宏。额外的参数是源文件名称和代码行号。MFC 可以使用此信息对程序员在调试模式下时报告内存泄漏。这适用于 MFC 类因为 MFC 提供的 新 接受额外的参数的重载的不同而不同。
但是,此扩展由预处理器来完成,因为它会影响所有使用 new 运算符。如果在项目中使用了任何非 MFC 类,其 new 运算符是也即使没有合适的重载,新 的可用在该类中扩展。这是发生在 GDI + 中,如此一来,您收到一个编译时错误消息。
(2)解决方法
方法一:通过注释掉以下行在源文件中的代码关闭预处理器扩展:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
注
: 此方法具有不使用的缺点在 MFC 中功能的信息,这些功能可帮助您跟踪内存分配和泄漏。
方法二:
GDI + 使用重载为提供 新 的和 删除 运算符通过编写一些代码,可接受,并丢弃其他参数。您可以将下面的代码演示了这种方法,粘贴到一个新的头文件,并包括新的头文件,而不是 Gdiplus.h 文件
Ensure that GdiPlus header files work properly with MFC DEBUG_NEW and STL header files.
#define iterator _iterator
#ifdef _DEBUG
namespace Gdiplus
{
namespace DllExports
{
#include <GdiplusMem.h>
};
#ifndef _GDIPLUSBASE_H
#define _GDIPLUSBASE_H
class GdiplusBase
{
public:
void (operator delete)(void* in_pVoid)
{
DllExports::GdipFree(in_pVoid);
}
void* (operator new)(size_t in_size)
{
return DllExports::GdipAlloc(in_size);
}
void (operator delete[])(void* in_pVoid)
{
DllExports::GdipFree(in_pVoid);
}
void* (operator new[])(size_t in_size)
{
return DllExports::GdipAlloc(in_size);
}
void * (operator new)(size_t nSize, LPCSTR lpszFileName, int nLine)
{
return DllExports::GdipAlloc(nSize);
}
void operator delete(void* p, LPCSTR lpszFileName, int nLine)
{
DllExports::GdipFree(p);
}
};
#endif // #ifndef _GDIPLUSBASE_H
}
#endif // #ifdef _DEBUG
#include <gdiplus.h>
#undef iterator
Ensure that Gdiplus.lib is linked.
#pragma comment(lib, "gdiplus.lib")