gdiplus exception
来源:互联网 发布:java list移除元素 编辑:程序博客网 时间:2024/06/07 20:38
<span style="font-size:14px;">#include <windows.h>#include <gdiplus.h>#include <stdio.h>using namespace Gdiplus;#pragma comment(lib, "gdiplus.lib")int main(){GdiplusStartupInput gdiplusStartupInput;ULONG_PTR gdiplusToken;GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);printf("%d\n", gdiplusStartupInput.GdiplusVersion);Image image(L"ing.png");printf("The width of the image is %u.\n", image.GetWidth());printf("The height of the image is %u.\n", image.GetHeight());GdiplusShutdown(gdiplusToken);return 0;}</span>
一个使用Gdiplus的Hello World程序,居然都出现了错误。输出居然没有问题=)。
因为这学期到下学期打算深入学习调试技术,一心想着不丢弃所遇到的任何一个bug。
F5跟踪一下:
在Image类的析构函数中出现一个Access violation 错误。
析构函数一般都是用来释放空间的,为什么会出错呢?
自认为很重要的一点:在main函数return语句没执行之前调用的Image类的析构函数。
回想下看MSDN GdiplusStartup、GdiplusShutdown里的一句话:
Remarks
You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.
也就是说我们在调用GdiplusShutdown以后再去delete某个对象,造成了这个Access violation错误。解决办法:
<span style="font-size:14px;">#include <windows.h>#include <gdiplus.h>#include <stdio.h>using namespace Gdiplus;#pragma comment(lib, "gdiplus.lib")int main(){GdiplusStartupInput gdiplusStartupInput;ULONG_PTR gdiplusToken;GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);{Image image(L"ing.png");printf("The width of the image is %u.\n", image.GetWidth());printf("The height of the image is %u.\n", image.GetHeight());}GdiplusShutdown(gdiplusToken);return 0;}</span>把gdi+处理函数放在一个{}内
或者
<span style="font-size:14px;">#include <windows.h>#include <gdiplus.h>#include <stdio.h>using namespace Gdiplus;INT main(){ GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Image *image = new Image(L"ing.png"); printf("The width of the image is %u.\n", image->GetWidth()); printf("The height of the image is %u.\n", image->GetHeight()); delete image; GdiplusShutdown(gdiplusToken); return 0;}</span>
0 0
- gdiplus exception
- GDIPLUS
- Gdiplus::DrawString
- GdiPlus使用方法
- GDIPlus装载
- 初次接触GDIplus
- MinGW 编译 GDIPlus 程序
- 关于gdiplus使用
- Gdiplus::Image::FromFile
- gdi gdiplus directx
- VC6 中使用GDIPlus
- VS2008,GDIPlus初步
- gdiplus.h的引用
- Gdiplus阴影文字实现
- using namespace Gdiplus;
- 新的 GdiPlus
- CImage转换Gdiplus::Bitmap
- gdiplus图片格式转换
- 并查集讲解
- jdk下载与安装
- Mathematician QSC(欧拉定理+矩阵快速幂)
- mean-shift based tracking回顾
- 数据挖掘
- gdiplus exception
- Intellij idea:Method breakpoints my dramatically slow down debugging
- 深度学习笔记3torch实现多层感知器
- z-index层级在IE中无效
- Node.js学习(二)——Node.js连接mysql数据库
- redis 总结
- union的特性,去重与不去重
- HashMap源码解读
- Storm 简介及组件的基本概念