因为没有仔细看文档

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. React Native :加载新闻列表

    代码地址如下:http://www.demodashi.com/demo/13212.html 标签与内容页联动 上一节(React Native : 自定义视图)做到了点击标签自动移动,还差跟下面的 ...

  2. 纪念我人生中第一个merge into语句

    做按组织关系汇总功能时,当数据量特别大,或者汇总组织特别多时,运行效率特别低,于是使用了merge into语句. 代码如下: public void updateInsertData(DataSet ...

  3. C# 获取当前路径方法(转)

    C# 获取当前路径方法 //获取包含清单的已加载文件的路径或 UNC 位置. public static string sApplicationPath = Assembly.GetExecuting ...

  4. Cocos2D-X2.2.3学习笔记10(几何图形)

    我们这节来学习几何图形,即怎样使用Cocos2d-x绘制各种图形.已经贝塞尔曲线 我们查看CCNode中有个draw函数,我们须要将绘制的代码所有写在这个函数里面.写在init函数里是画不出线来的, ...

  5. TensorFlow学习笔记 补充2—— 生成特殊张量

    1. 生成tensor tf.zeros(shape, dtype=tf.float32, name=None) tf.zeros_like(tensor, dtype=None, name=None ...

  6. win10虚拟环境安装scrapy

    说明:本人用的是python3.6版本,64位系统. 第一步:创建并激活虚拟环境 virtualenv scrapy scrapy\Scripts\activate 第二步:安装lxml pip in ...

  7. formail 发送HTML 邮件通过 SENDMAIL

    cat a.html | formail -I "Content-type:text/html;charset=utf-8" -I "Subject:layer4 con ...

  8. js中级四: 跨域

    原文链接:http://www.cnblogs.com/scottckt/archive/2011/11/12/2246531.html 什么是跨域? 首先什么是跨域,简单地理解就是因为JavaScr ...

  9. Trees in a Wood. UVA 10214 欧拉函数或者容斥定理 给定a,b求 |x|<=a, |y|<=b这个范围内的所有整点不包括原点都种一棵树。求出你站在原点向四周看到的树的数量/总的树的数量的值。

    /** 题目:Trees in a Wood. UVA 10214 链接:https://vjudge.net/problem/UVA-10214 题意:给定a,b求 |x|<=a, |y|&l ...

  10. implode 把数组 组成一个字符串

    $data=array(1,2,3,4,5); implode(",",$data);