开发者

Access violation in Image destructor

开发者 https://www.devze.com 2023-01-09 10:29 出处:网络
A very simple program I might say.. #include <windows.h> #include <gdiplus.h> using namespace Gdiplus;

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;
}

When running this example I get an access violation in GdiplusBitmap.h in this function

inline 
Image::~Image()
{
    DllExports::GdipDisposeImage(nativeImage);
}

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 t开发者_C百科he Bitmap constructor, but didn't find anything.)

What am I missing?


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.

The error should go away if you make sure that bitmap is deleted before you shutdown GDI+.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号