为什么调用 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 ...
随机推荐
- OgnlValueStack:49 - Error setting expression 'sfjmyh.zdyx6' with value '[Ljava.lang.String;@28d320d6'
作过户管理流程时,提交表单后控制台显示如下错误 : WARN com.opensymphony.xwork2.ognl. OgnlValueStack:60 - Error setting expre ...
- (二)Oracle学习笔记—— 序列
1. 序列简介 序列作为数据库里的对象,可以将序列值装入内存以提高访问效率,主要作用是生成唯一的主键值.其作用相当于一个计数器,它并不会与特定的表关联.通过创建Oracle序列和触发器实现表的主键自增 ...
- 轻量级代码生成器-OnlyCoder 第一篇
程序猿利器:代码生成器,使用代码生成器已经好几年了,增删改查各种生成,从UI到DATA层均生成过.之前有使用过动软的,T4模板等.... T4生成实体还是没有问题的,但是生成MVC视图就有点烦杂了, ...
- NodeJS在CentOs7下安装
node下载地址:https://nodejs.org/en/download/ 1.安装gcc $ yum install gcc-c++ 2.解压最新版本 $ mkdir /usr/local/n ...
- Python绘制分段函数
1.绘制分段函数:y=4sin(4πt)-sgn(t-0.3)-sgn(0.72-t) import numpy as npimport matplotlib.pyplot as plt#绘制分段函数 ...
- 字符串算法之 AC自己主动机
近期一直在学习字符串之类的算法,感觉BF算法,尽管非常easy理解,可是easy超时,全部就想学习其它的一些字符串算法来提高一下,近期学习了一下AC自己主动机.尽管感觉有所收获,可是还是有些朦胧的感觉 ...
- Atitit. 木马病毒的外部class自动加载机制------加载class的方法总结
Atitit. 木马病毒的外部class自动加载机制------加载class的方法总结 Atitit.java load class methods 1. 动态加载jar文件和class文件. 1 ...
- JavaScript Creating 对象
可通过多种方法在 JavaScript 中创建你自己的对象.可以直接实例化Object 对象 (JavaScript),然后添加你自己的属性和方法.或者可以使用对象文本表示法来定义你的对象.还可使用构 ...
- PHP excel读取excel文件转换为数组
/*备注:先去下载PHP EXCEL——http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=phpexcel&am ...
- http加密原理
HTTPS原理 客户端向服务器发送请求 服务器向客户端发送自己的证书 客户端验证证书的有效性(是否是可信用机构CA颁发的证书,如果不是则提出警告)并对比里面信息是否正确,不通过则立刻断开连接 向服务器 ...