gdi+在Graphics遇到的new 问题。

如果在gdi+中使用 如下:Graphics * graphics = new Graphics(pDc->m_hDC); 那么它就会报错,原因如下:

http://support.microsoft.com/kb/317799/en-us 。。 是因为在调试版本下,mfc的宏扩展,将new 运算符扩展为三个参数, 另外两个额外参数分别是source file name 和code line numbe。如果使用非mfc类,就会出现问题,所以在新类中还要重载如下new 和delete :

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);
}
即可

 

方法,可以在 gdi+的源代码 graphicsbase.h 中补上

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);
}
即可

ps: 如果删除 Graphics 对象,则应该在  GdiplusShutdown(gdiplusToken); 之前,否则报错。如下

 delete m_graphics;
 GdiplusShutdown(gdiplusToken);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
//以下假设你已经配置好VC6的GDI+环境 1.新建一个基于CScrollView的单文档程序, 2.在stdafx.h内添加如下代码: #ifndef ULONG_PTR #define ULONG_PTR unsigned long* #endif #include "GdiPlus.h" using namespace Gdiplus; #pragma comment(lib,"gdiplus.lib") 3.在GdiApp.h里的CGdiAppApp中加入两个成员: GdiplusStartupInput m_gdiplusStartupInput;// ULONG_PTR m_pGdiToken;// 4.在GdiApp.cpp中的CGdiAppApp构造函数CGdiAppApp()添加如下代码: GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL);// 5.在GdiApp.h里给CGdiAppApp添加一个析构函数~CGdiAppApp(); 6.在GdiApp.cpp中添加CGdiAppApp的析构函数~CGdiAppApp(): CGdiAppApp::~CGdiAppApp()// { GdiplusShutdown(m_pGdiToken);// } 7.在GdiAppView.h的CGdiAppView中添加成员变量: Bitmap* m_pbmp; 并在GdiAppView.cpp中的GdiAppView构造函数和析构函数中添加如下代码: CGdiAppView::CGdiAppView():m_pbmp(0)// { // TODO: add construction code here } CGdiAppView::~CGdiAppView() { delete m_pbmp;// m_pbmp=0;// } 8.按Ctrl+W,在弹出的对话框里选择Message Maps选项卡 class name选择CGdiAppView Object IDs里选中ID_FILE_OPEN 然后在Message里双击COMMAND 弹出的对话框选择Ok 这时会在Member functions:里多出一条刚添加进去的消息映射函数 双击它会自动跳转进入GdiAppView.cpp中的void CGdiAppView::OnFileOpen()函数处 然后添加如下代码: void CGdiAppView::OnFileOpen() { //见源码处 } 9.为了使8处代码有用,还需要: 在GdiAppView.h里添加两个函数声明: int A2U(const char* szA,wchar_t* szU,size_t cnt);// std::wstring A2U(const char* szA);// 并#include 然后在GdiAppView.cpp里加入这两个函数的实现 10.在GdiAppView.cpp中的OnDraw函数中添加显示代码: void CGdiAppView::OnDraw(CDC* pDC) { //见源码处 } 11.结束.有问题联系hastings1986@163.com //可能你Debug版本编译不过,则打开Gdi+的头文件GdiPlusBase.h //并修改为如下(其实就加了两个重载版本的newdelete): #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 in_size,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

睡在床板下_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值