<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>

gdiplus exception的更多相关文章

  1. 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 ~/ ...

  2. 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 的 ...

  3. .NET Core2.1项目在Linux上使用验证码报Unable to load shared library 'gdiplus' or one of its dependencies

    -- ::, 线程ID:[] 日志级别:ERROR 出错类:WebApp.HttpGlobalExceptionFilter property:[(null)] - 错误描述:System.TypeI ...

  4. [C#] C# 知识回顾 - 你真的懂异常(Exception)吗?

    你真的懂异常(Exception)吗? 目录 异常介绍 异常的特点 怎样使用异常 处理异常的 try-catch-finally 捕获异常的 Catch 块 释放资源的 Finally 块 一.异常介 ...

  5. 浅谈java异常[Exception]

    学习Java的同学注意了!!! 学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入Java学习交流群,群号码:589809992 我们一起学Java! 一. 异常的定义 在<java编程思想 ...

  6. 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" ...

  7. Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V

    在学习CGlib动态代理时,遇到如下错误: Exception in thread "main" java.lang.NoSuchMethodError: org.objectwe ...

  8. Atitit 解决Unhandled event loop exception错误的办法

    Atitit 解决Unhandled event loop exception错误的办法 查看workspace/.metadata/.log org.eclipse.swt.SWTError: No ...

  9. Java中的Checked Exception——美丽世界中潜藏的恶魔?

    在使用Java编写应用的时候,我们常常需要通过第三方类库来帮助我们完成所需要的功能.有时候这些类库所提供的很多API都通过throws声明了它们所可能抛出的异常.但是在查看这些API的文档时,我们却没 ...

随机推荐

  1. 大数据-HDFS 集群搭建的配置文件

    1.HDFS简单版集群搭建相关配置文件 1.core-site.xml文件 <property> <name>fs.defaultFS</name> <val ...

  2. 1092 最好吃的月饼 (20分)C语言

    月饼是久负盛名的中国传统糕点之一,自唐朝以来,已经发展出几百品种. 若想评比出一种"最好吃"的月饼,那势必在吃货界引发一场腥风血雨-- 在这里我们用数字说话,给出全国各地各种月饼的 ...

  3. nor flash之写保护

    背景 没有电池的嵌入式设备,很容易发生随机掉电.因此要让产品可靠稳定,就必须保证各种场景下的掉电安全. 例如系统更新过程随机掉电,不能导致系统无法启动.例如正常读写flash过程中掉电,最多正在传输的 ...

  4. JavaScript面向对象 实例与原型

    JavaScript 面向对象 和 C# 不太一样,js 的对象是继承自原型的如下: 首先创建一个 js 实例 new  function function f () {} 这个函数 会继承 Func ...

  5. qiniuLive 连麦流程介绍

    本文出自APICloud官方论坛 qiniuLive 封装了七牛直播云服务平台的移动端开放 SDK.该模块包括视频流采集和视频流播放两部分 iOS连麦流程图: Android连麦流程图: 以下部分代码 ...

  6. dfs - 卡一个无符号长整形

    Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal repr ...

  7. Linux下搭建Jmeter+Ant+Jenkins自动化测试框架

    前言 在之前的文章中,我们学习了通过Ant调用Jmeter脚本生成HTML测试报告,但未实现自动执行脚本生成报告,同时生成的报告是在Linux下,查看报告很不方便.因此,我们将结合Jenkins来进一 ...

  8. 12、python文件的操作

    前言:本文主要介绍python中文件的操作,包括打开文件.读取文件.写入文件.关闭文件以及上下文管理器. 一.打开文件 Python open() 方法用于打开一个文件,并返回文件对象,在对文件进行处 ...

  9. python类型-序列

    注:本文档主要是学习<Python核心编程(第二版)>时做的资料整理. 1.序列 序列的成员是有序排列的,并且可以通过下标偏移量访问到它的一个或者几个成员,包括字符串(普通字符串和Unic ...

  10. 夜晚 十点 React-Native 源码 暴力畜 系列

    百度 上 给的 关于 React-Native 的 排名 前三 继续 跟