图片析构函数中的访问冲突 [英] Access violation in Image destructor
问题描述
我可能会说一个非常简单的程序。
A very simple program I might say..
#include <windows.h>
#include <gdiplus.h>
using namespace Gdiplus;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR cmdLine, int nShow){
// Gdiplus variables
GdiplusStartupInput mGdiplusStartupInput;
ULONG_PTR mGdiplusToken;
GdiplusStartup(&mGdiplusToken, &mGdiplusStartupInput, NULL);
Bitmap bitmap(L"left.bmp");
GdiplusShutdown(mGdiplusToken);
return 0;
}
在运行此示例时,此函数在GdiplusBitmap.h中出现访问冲突
When running this example I get an access violation in GdiplusBitmap.h in this function
inline
Image::~Image()
{
DllExports::GdipDisposeImage(nativeImage);
}
通过删除对 Bitmap bitmap(L left.bmp);
一切正常。.我试图在msdn上找到一个简单的示例(例如位图构造函数,但未找到任何内容。)
By removing the call to Bitmap bitmap(L"left.bmp");
everything works fine.. I tried to find a simple example on msdn (for instance somewhere near the Bitmap constructor, but didn't find anything.)
我缺少什么?
推荐答案
您创建的位图
实例正在下降在调用关闭GDI +之后超出范围。因此,当位图
被破坏时,它无法调用给定的 GdipDisposeImage
方法。
The Bitmap
instance you created is falling out of scope AFTER the call to shutdown GDI+. So when the Bitmap
gets destructed, it cannot call the given GdipDisposeImage
method.
如果在关闭GDI +之前确保已删除位图
,则错误应消失。
The error should go away if you make sure that bitmap
is deleted before you shutdown GDI+.
这篇关于图片析构函数中的访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!