为什么调用 GdiplusShutdown 函数会在 DllExports::GdipDeleteGraphics(nativeGraphics) 位置抛出异常?
因为没有仔细看文档
https://docs.microsoft.com/en-us/windows/desktop/api/Gdiplusinit/nf-gdiplusinit-gdiplusshutdown
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.
抛异常
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
HDC deskTop = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(deskTop, BITSPIXEL);
int nWidth = GetDeviceCaps(deskTop, HORZRES);
int nHeight = GetDeviceCaps(deskTop, VERTRES);
//int center
Gdiplus::Graphics graphics(deskTop);
graphics.TranslateTransform(nWidth / 2, nHeight / 2);
Gdiplus::Image *image = new Gdiplus::Image(L"D:\\456.png");
printf("%dx%d BitPerPixel = %d\r\n", nWidth, nHeight, nBitPerPixel);
graphics.DrawImage(image, -256 / 2, -256 / 2, 256, 256);
delete image;
image = nullptr;
ReleaseDC(NULL, deskTop);
Gdiplus::GdiplusShutdown(gdiplusToken);
使用 {} 大阔号把 gdi+ 的对象作用域分开,当离开作用域时,此时 gdi+ 对象的使用资源会释放掉,然后调用 Gdiplus::GdiplusShutdown(gdiplusToken); 函数就不会抛异常了。you must delete all of your GDI+ objects (or have them go out of scope) before you call GdiplusShutdown.
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
{
HDC deskTop = GetDC(NULL);
int nBitPerPixel = GetDeviceCaps(deskTop, BITSPIXEL);
int nWidth = GetDeviceCaps(deskTop, HORZRES);
int nHeight = GetDeviceCaps(deskTop, VERTRES);
//int center
Gdiplus::Graphics graphics(deskTop);
graphics.TranslateTransform(nWidth / 2, nHeight / 2);
Gdiplus::Image *image = new Gdiplus::Image(L"D:\\456.png");
printf("%dx%d BitPerPixel = %d\r\n", nWidth, nHeight, nBitPerPixel);
graphics.DrawImage(image, -256 / 2, -256 / 2, 256, 256);
delete image;
image = nullptr;
ReleaseDC(NULL, deskTop);
}
Gdiplus::GdiplusShutdown(gdiplusToken);
为什么调用 GdiplusShutdown 函数会在 DllExports::GdipDeleteGraphics(nativeGraphics) 位置抛出异常?的更多相关文章
- ng-repeat循环出来的部分调用同一个函数并且实现每个模块之间不能相互干扰
使用场景:用ng-repeat几个部分,每个部分调用同一个函数,但是每个模块之间的功能不能相互干扰 问题:在用repeat实现.content块repeat的时候打算这样做:新建一个空的数组(nmbe ...
- 深入理解javascript系列(4):立即调用的函数表达式
本文来自汤姆大叔 前言 大家学JavaScript的时候,经常遇到自执行匿名函数的代码,今天我们主要就来想想说一下自执行. 在详细了解这个之前,我们来谈了解一下“自执行”这个叫法,本文对这个功能的叫法 ...
- EC笔记,第二部分:9.不在构造、析构函数中调用虚函数
9.不在构造.析构函数中调用虚函数 1.在构造函数和析构函数中调用虚函数会产生什么结果呢? #; } 上述程序会产生什么样的输出呢? 你一定会以为会输出: cls2 make cls2 delete ...
- EC笔记,第二部分:5.了解C++默默编写并调用哪些函数
5.了解C++默默编写并调用哪些函数 1.C++空类 C++会为一个空类建立以下函数 (1).默认构造函数 (2).默认拷贝构造函数 (3).析构函数 (4).赋值运算符(如果成员包含引用类型或con ...
- C++构造函数中不能调用虚函数
在构造函数中调用虚函数,并不会产生多态的效果,就跟普通函数一样. c++ primer 第四版中497页15.4.5构造函数和析构中的虚函数讲到,如果在构造函数或析构函数中调用虚函数,则运行的是为构造 ...
- ZeroMQ接口函数之 :zmq_errno – 返回errno的值给调用此函数的线程
ZeroMQ 官方地址 :http://api.zeromq.org/4-0:zmq_errno zmq_errno(3) ØMQ Manual - ØMQ/3.2.5 Name zm ...
- cocos2dx 3.x(获得父类的node型指针调用父类函数this->getParent())
void CenterLayer::zhanzheng(CCObject* pSender){ ((GameScene*)this->getParent())->showLayer(Gam ...
- 09——绝不在构造和析构函数中调用virtual函数
在base class构造期间,virtual函数不是virtual函数. 构造函数.析构函数中不要调用virtual函数.
- LR常用函数以及调用自定义函数
2.LR常用函数以及调用自定义函数 2.1.LR常用函数以及对信息的判断 2.1.1. LR内部自定义函数 在LR脚本中定义变量和编写自定义函数,需将变量的声明放在脚本其他内容的上方,否则会提示[il ...
随机推荐
- JPA学习笔记1——JPA基础 (转自CSDN)
http://blog.csdn.net/chjttony/article/details/6086298 1.JPA简介: Java持久化规范,是从EJB2.x以前的实体Bean(Entity be ...
- linux学习一个服务(未完)
学习一个服务的过程 1.了解服务的作用:名字 功能,特点 2.安装 3.配置文件位置,端口 4.服务启动关闭的脚本 5.此服务的使用方法 6.修改配置文件,实战举例 7.排错(从下到上,从内到外)
- Linux管理员必须知道的sudo命令
"Sudo"是Unix/Linux平台上的一个很实用的工具,它同意系统管理员分配给普通用户一些合理的"权利",让他们执行一些仅仅有超级用户或其它 特许用户才干完 ...
- Atitit.uml2 api 的编程代码实现设计uml开发 使用eclipse jar java 版本
Atitit.uml2 api 的编程代码实现设计uml开发 使用eclipse jar java 版本 1. clipse提供了UML的底层Java包, 1 2. MDTUML2Getting St ...
- vivado与modelsim的联合仿真(二)
最近在做Zynq的项目,曾经尝试使用ISE+PlanAhead+XPS+SDK组合和Vivado+SDK来搭建工程,使用中发现前者及其不方便后者有诸多不稳定.近期得闻Xilinx退出Vivado20 ...
- jquery中Uncaught TypeError: $(...).ajaxUpload is not a function(…)错误解决方法
错误原因:该函数不是jquery的核心函数,所以需要外部引入ajaxfileupload.js文件,可能是没有引入,或者引入的js文件互相冲突 解决方法:每次进入一个函数之前打印该函数所有的js文件, ...
- MySQL 中文显示乱码
最近关于中文显示乱码的贴子比较多,所以也做了个总结: 可以参考一下杨涛涛版主的<各种乱码问题汇总> http://topic.csdn.net/u/20071124/08/3b7eae69 ...
- 2017-5-14 湘潭市赛 Longest Common Subsequence 想法题
Longest Common Subsequence Accepted : Submit : Time Limit : MS Memory Limit : KB Longest Common Subs ...
- python第四周迭代器生成器序列化面向过程递归
第一节装饰器复习和知识储备------------ 第一节装饰器复习和知识储备------------ def wrapper(*args,**kwargs): index(*args,**kwa ...
- Oracle----oracle 事务总结
用了这么长时间的oracle,该总结一下所得了 1,事务 事务用于保证数据的一致性, 它由一组相关的 dml语句组成, 该组的dml(数据操作语言,增删改,没有查询)语句要么全部成功,要么全部失败,比 ...