<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. 使用宝塔搭建nextcloud的过程(搭建、优化、问题)

    宝塔部署教程 参考网址: 使用NextCloud来搭建我们的私有网盘.并结合Redis优化性能(宝塔) https://www.moerats.com/archives/175/ 宝塔面板下nextc ...

  2. 如何选择API测试工具

    没有最好,只有最合适. 如今,越来越多的公司正在向DevOps的方向左转,以实现持续集成和持续部署开发.这意味着我们的反馈需要比以往更快,以便确定我们的应用程序是否准备好交付.这就是API测试如此重要 ...

  3. 「USACO11NOV」牛的障碍Cow Steeplechase 解题报告

    题面 横的,竖的线短段,求最多能取几条没有相交的线段? 思路 学过网络流的童鞋在哪里? 是时候重整网络流雄风了! 好吧,废话不多说 这是一道最小割的题目 怎么想呢? 要取最多,那反过来不就是不能取的要 ...

  4. spring cloud微服务快速教程之(三)声明式访问Feign、负载均衡Ribbon

    0-前言 eureka实际上已经集成了负载均衡调度框架Ribbon: 我们有了各个微服务了,那怎么来调用他们呢,一种方法是可以使用 RestTemplate(如:String str= restTem ...

  5. Java框架之Spring01-IOC-bean配置-文件引入-注解装配

    Spring 框架,即framework.是对特定应用领域中的应用系统的部分设计和实现的整体结构.就相当于让别人帮你完成一些基础工作,它可以处理系统很多细节问题,而且框架一般是成熟,稳健的. Spri ...

  6. APICloud开发者进阶之路 |纯手工编写日程表功能

    本文出自APICloud官方论坛, 感谢论坛版主 赵永亮 的分享. 最近看论坛内关于极光推送的问题有很多, 本想写一个关于极光的详细教程的,无奈已经有很多大牛分享过了,所以只得纯手工写了一个日程表,可 ...

  7. 区间dp - 括号匹配并输出方案

    Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular seque ...

  8. 幽灵java进程引起的: FATAL ERROR in native method

    FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT( ...

  9. Nginx代理服务——正向代理

    正向代理 在/opt/app/code的目录下创建一个joy.html文件 <html> <head> <meta charset="utf-8"&g ...

  10. [bzoj5507] [洛谷P5305] [gzoi2019]旧词

    Descriptioin 浮生有梦三千场 穷尽千里诗酒荒 徒把理想倾倒 不如早还乡 温一壶风尘的酒 独饮往事迢迢 举杯轻思量 泪如潮青丝留他方 --乌糟兽/愚青<旧词> 你已经解决了五个问 ...