gdiplus exception
<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里的一句话:
RemarksYou must call GdiplusStartup before |
也就是说我们在调用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>
gdiplus exception的更多相关文章
- the type initializer for 'system.drawingcore.gdiplus' threw an exception
Centos 7 yum install libgdiplus-devel reboot之后生效 apt install libgdiplus cp /usr/lib/libgdiplus.so ~/ ...
- ASP.Net Core "The type initializer for 'Gdip' threw an exception"
ASP.NET Core项目部署在Linux下可能会出现GDI错误 The type initializer for 'Gdip' threw an exception 解决方案:创建 libdl 的 ...
- .NET Core2.1项目在Linux上使用验证码报Unable to load shared library 'gdiplus' or one of its dependencies
-- ::, 线程ID:[] 日志级别:ERROR 出错类:WebApp.HttpGlobalExceptionFilter property:[(null)] - 错误描述:System.TypeI ...
- [C#] C# 知识回顾 - 你真的懂异常(Exception)吗?
你真的懂异常(Exception)吗? 目录 异常介绍 异常的特点 怎样使用异常 处理异常的 try-catch-finally 捕获异常的 Catch 块 释放资源的 Finally 块 一.异常介 ...
- 浅谈java异常[Exception]
学习Java的同学注意了!!! 学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入Java学习交流群,群号码:589809992 我们一起学Java! 一. 异常的定义 在<java编程思想 ...
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
学习架构探险,从零开始写Java Web框架时,在学习到springAOP时遇到一个异常: "C:\Program Files\Java\jdk1.7.0_40\bin\java" ...
- Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...
- Atitit 解决Unhandled event loop exception错误的办法
Atitit 解决Unhandled event loop exception错误的办法 查看workspace/.metadata/.log org.eclipse.swt.SWTError: No ...
- Java中的Checked Exception——美丽世界中潜藏的恶魔?
在使用Java编写应用的时候,我们常常需要通过第三方类库来帮助我们完成所需要的功能.有时候这些类库所提供的很多API都通过throws声明了它们所可能抛出的异常.但是在查看这些API的文档时,我们却没 ...
随机推荐
- Windows服务器管理--批量管理工具
iis7批量远程控制: 一款电脑远程监控的工具,IIS7远程桌面管理是一款专业的远程桌面连接软件,无需安装.操作简单方便.完美的界面设计.强大的监控功能.稳定的系统平台,满足了用户实现远程桌面连接的需 ...
- 浅谈Java中接口与抽象类的异同
浅谈Java中接口与抽象类的异同 抽象类和接口这两个概念困扰了我许久,在我看来,接口与抽象类真的十分相似.期间也曾找过许许多多的资料,参考了各路大神的见解,也只能是简简单单地在语法上懂得两者的区别.硬 ...
- HDU3886 Final Kichiku “Lanlanshu” 题解 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3886 题目大意: 给一定区间 \([A,B]\) ,一串由 /, \ , - 组成的符号串.求满足符号 ...
- 2017 ACM-ICPC亚洲区域赛北京站J题 Pangu and Stones 题解 区间DP
题目链接:http://www.hihocoder.com/problemset/problem/1636 题目描述 在中国古代神话中,盘古是时间第一个人并且开天辟地,它从混沌中醒来并把混沌分为天地. ...
- DNS服务器红帽5.4搭建图文教程!!!
DNS服务器 挂载光盘 mount 查看光盘所在位置 mount -t iso9660 设备目录 /mnt 表示挂载 软件包安装 所有软件包都在Server目录下 rpm -ivh /mnt/Serv ...
- 03_常用的JS正则表达式54种形式类型
1.由数字.26个英文字母或者下划线组成的字符串: ^[0-9a-zA-Z_]{1,}$ 2.非负整数(正整数 + 0 ): ^/d+$ 3. 正整数: ^[0-9]*[1-9][0-9]*$ 4.非 ...
- 通俗易懂理清mybatis中SqlSessionSql、SqlSessionTemplate、SessionFactory和SqlSessionFactoryBean之间的关系
我潇洒的灰大狼又回来啦.今天送大家的一句话是: 保持耐心,永远年轻,永远热泪盈眶. 前言 先容我哭一会儿,呜呜呜~昨晚写了一半的文章,还没保存就盖上盖子准备回家,拔下电源准备把电脑塞进书包带回家完成时 ...
- ElementUi 表格取消全选框,用文字表示
Echarts ElementUi 表格取消全选框,用文字表示 1.先看看实现的图 一. 添加添加复选框列 <el-table v-loading="zongShipLoading&q ...
- ubuntu(linux)虚拟主机部署桌面,使用window链接
买的ubuntu只有命令行,想安装一个桌面,远程操控 网上教程很多,我主要遇到一个问题,百思不得其解 之间安装的不是连接超时,就是拒绝连接 又重新参考这篇博客安装后才解决 说一下大致流程,详细的见这位 ...
- 使用Java实现简单的Http服务器
在Java中可以使用HttpServer类来实现Http服务器,该类位于com.sun.net包下(rt.jar).实现代码如下: 主程序类 package bg.httpserver; import ...