因为没有仔细看文档

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) 位置抛出异常?的更多相关文章

  1. ng-repeat循环出来的部分调用同一个函数并且实现每个模块之间不能相互干扰

    使用场景:用ng-repeat几个部分,每个部分调用同一个函数,但是每个模块之间的功能不能相互干扰 问题:在用repeat实现.content块repeat的时候打算这样做:新建一个空的数组(nmbe ...

  2. 深入理解javascript系列(4):立即调用的函数表达式

    本文来自汤姆大叔 前言 大家学JavaScript的时候,经常遇到自执行匿名函数的代码,今天我们主要就来想想说一下自执行. 在详细了解这个之前,我们来谈了解一下“自执行”这个叫法,本文对这个功能的叫法 ...

  3. EC笔记,第二部分:9.不在构造、析构函数中调用虚函数

    9.不在构造.析构函数中调用虚函数 1.在构造函数和析构函数中调用虚函数会产生什么结果呢? #; } 上述程序会产生什么样的输出呢? 你一定会以为会输出: cls2 make cls2 delete ...

  4. EC笔记,第二部分:5.了解C++默默编写并调用哪些函数

    5.了解C++默默编写并调用哪些函数 1.C++空类 C++会为一个空类建立以下函数 (1).默认构造函数 (2).默认拷贝构造函数 (3).析构函数 (4).赋值运算符(如果成员包含引用类型或con ...

  5. C++构造函数中不能调用虚函数

    在构造函数中调用虚函数,并不会产生多态的效果,就跟普通函数一样. c++ primer 第四版中497页15.4.5构造函数和析构中的虚函数讲到,如果在构造函数或析构函数中调用虚函数,则运行的是为构造 ...

  6. ZeroMQ接口函数之 :zmq_errno – 返回errno的值给调用此函数的线程

    ZeroMQ 官方地址 :http://api.zeromq.org/4-0:zmq_errno zmq_errno(3)         ØMQ Manual - ØMQ/3.2.5 Name zm ...

  7. cocos2dx 3.x(获得父类的node型指针调用父类函数this->getParent())

    void CenterLayer::zhanzheng(CCObject* pSender){ ((GameScene*)this->getParent())->showLayer(Gam ...

  8. 09——绝不在构造和析构函数中调用virtual函数

    在base class构造期间,virtual函数不是virtual函数. 构造函数.析构函数中不要调用virtual函数.

  9. LR常用函数以及调用自定义函数

    2.LR常用函数以及调用自定义函数 2.1.LR常用函数以及对信息的判断 2.1.1. LR内部自定义函数 在LR脚本中定义变量和编写自定义函数,需将变量的声明放在脚本其他内容的上方,否则会提示[il ...

随机推荐

  1. ps -ef/ps -aux 查看正在活动的进程

    ps -ef 查看正在活动的进程 ps -ef |grep abc 查看含有"abc"的活动进程 ps -ef |grep -v abc 查看不含abc的活动进程 1)ps a 显 ...

  2. 经典SQL语句使用方法大全

    一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数 ...

  3. Ant 编译项目资源不足

    http://www.cnblogs.com/interboy/archive/2008/07/15/1243265.html今天用ant编译项目出现 [javac] 系统资源不足.的错误,如下 Bu ...

  4. ajax请求web容器控制超时

    1.项目用到超时控制,针对ajax请求超时,可以参照如下解决方案 tomcat容器 web.xml 中配置 <session-config> <session-timeout> ...

  5. ScrollView嵌套ListView冲突问题的最优解决方式

    项目做多了之后.会发现事实上ScrollView嵌套ListVew或者GridView等非经常常使用,可是你也会发现各种奇怪问题产生.依据个人经验如今列出常见问题以及代码最少最简单的解决方法. 问题一 ...

  6. sql中的笛卡尔积

    sql中的笛卡尔积 我们对数据库表进行操作时,经常会对多张表进行关联,多表连接查询大家肯定不会陌生,但是一不小心很容易出来庞大冗余的数据. 笛卡尔积数学概念 笛卡尔积是指在数学中,两个集合X和Y的笛卡 ...

  7. python 在Windows中描述路径时出现的问题

    问题的根本:windows读取文件可以用\,但在字符串里面\被作为转义字符使用,   python在描述路径时有两种方式: 'd:\\a.txt',转义的方式 r'd:\a.txt',声明字符串不需要 ...

  8. Atitit. Ati IDE 开发平台的第一版规划

    Atitit. Ati IDE 开发平台的第一版规划 1. 增加业务类型复杂类型内置1 1.1. 简单类型string int float自动类型转换以及2 1.2. $变量str连接2 2. Dsl ...

  9. 推送本地文件夹到github

    1.首先鼠标右键,Git Init Here将文件夹初始化为仓库 2.打开github桌面版 3.点击添加本地仓库 4.填好summary和description并提交 5.push到自己的githu ...

  10. Django中的request对象组成

    if  request.REQUEST.has_key('键值'): HttpRequest对象的属性 参考: 表 H-1. HttpRequest对象的属性 属      性 描述 path 表示提 ...