为什么调用 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 ...
随机推荐
- mac下安装python pip、pyspider
如果mac下没有安装wget,还需要安装wget,见http://www.cnblogs.com/cocowool/archive/2012/06/24/2560574.html 使用 pip 安装 ...
- Spring属性占位符 PropertyPlaceholderConfigurer
http://www.cnblogs.com/yl2755/archive/2012/05/06/2486752.html PropertyPlaceholderConfigurer是个bean工厂后 ...
- 【MyBatis学习13】MyBatis中的二级缓存
1. 二级缓存的原理 前面介绍了,mybatis中的二级缓存是mapper级别的缓存,值得注意的是,不同的mapper都有一个二级缓存,也就是说,不同的mapper之间的二级缓存是互不影响的.为了更加 ...
- js标准化价钱
//标准化总价钱 s:总价钱,n:保留几位小数 function fmoney(s, n) { n = n > 0 && n <= 20 ? n : 2; s = pars ...
- CentOS6.5配置PHP CI程序
步骤: 1.安装CentOS6.5系统: 1.选择PHP+Mysql环境 2.关闭防火墙和SeLinux 1.chkconfig --level 35 iptables off ...
- random实现验证码功能
直接上代码: #-*- coding: utf-8 -*- #一个简单的验证码程序 import random #定义一个全局变量,初始值为空字符串 checkcode = '' for i in r ...
- SpringMVC学习(一)小demo
首先看一下整个demo的项目结构: 第一步是导入Spring MVC单独使用时的最少jar包: 第二步在项目的web.xml中配置Spring MVC提供的拦截请求的Servlet: 全类名是:org ...
- Nandflash镜像尾部不应填充0xFF
Nandflash镜像文件系统尾部经常被填充0xFF以补齐大小,这样做是错误的,可能会有意想不到的bug.包括JFFS2.UBIFS等. 因此建议丢弃多余的0xFF. 出自:http://www.li ...
- abp 列表和明细页面的规则说明
0>列表区域mainviewbody 1>列表头mainviewheader 名称 2>列表条件mainviewcodtionbody 条件区 3>列表工具栏mainviewt ...
- ftp 下载最近一小时的文件
#!/bin/bash #cd /home/ftptmp/ ftp -v -n 192.168.0.100 2121 <<EOF user test 2009 binary cd OU ...