Thales Medeiros
June 4th, 2006, 02:58 AM
Hi, all!
I read a post here about Access Violation with GDI+, and the problem had been solved when the user simply called the GdiplusStartup() function. In my case this function is already being called, and the problem is a little different.
I created a class that Load JPG files from the executable resource. The class is something like this:
class TJPGResource {
public:
TJPGResource() {}
virtual ~TJPGResource() {}
bool Load(UINT ResourceID, LPCTSTR ResourceType);
Gdiplus::Bitmap *GetBitmap() {return pBitmap;}
private:
Gdiplus::Bitmap *pBitmap;
};
bool TJPGResource::Load(UINT ResourceID, LPCTSTR ResourceType) {
/*
Some code here to load the image data to the variable hBuffer
*/
IStream *pStream;
if(CreateStreamOnHGlobal(hBuffer, FALSE, &pStream)==S_OK) {
//************************************************
pBitmap=new Gdiplus::Bitmap(pStream);
//Here the program crashes with an Access Violation message
//************************************************
//************************************************
Gdiplus::Bitmap *localBitmap=new Gdiplus::Bitmap(pStream);
//This code works OK in place of the original above, but that's not what I want
//************************************************
}
}
Doesn't need to say that I'm using GdiplusStartup(), and of course the "using namespace Gdiplus;" is in the code.
For me it's not a GDI+ problem. In fact, when I try to put any value to the pBitmap variable, like point it to NULL, the program crashes too. I've already put this member as private, protected and public. In all cases the problem is the same.
Thanks for the attention of all! Hope u can help me with this headache.
Thales Medeiros.
I read a post here about Access Violation with GDI+, and the problem had been solved when the user simply called the GdiplusStartup() function. In my case this function is already being called, and the problem is a little different.
I created a class that Load JPG files from the executable resource. The class is something like this:
class TJPGResource {
public:
TJPGResource() {}
virtual ~TJPGResource() {}
bool Load(UINT ResourceID, LPCTSTR ResourceType);
Gdiplus::Bitmap *GetBitmap() {return pBitmap;}
private:
Gdiplus::Bitmap *pBitmap;
};
bool TJPGResource::Load(UINT ResourceID, LPCTSTR ResourceType) {
/*
Some code here to load the image data to the variable hBuffer
*/
IStream *pStream;
if(CreateStreamOnHGlobal(hBuffer, FALSE, &pStream)==S_OK) {
//************************************************
pBitmap=new Gdiplus::Bitmap(pStream);
//Here the program crashes with an Access Violation message
//************************************************
//************************************************
Gdiplus::Bitmap *localBitmap=new Gdiplus::Bitmap(pStream);
//This code works OK in place of the original above, but that's not what I want
//************************************************
}
}
Doesn't need to say that I'm using GdiplusStartup(), and of course the "using namespace Gdiplus;" is in the code.
For me it's not a GDI+ problem. In fact, when I try to put any value to the pBitmap variable, like point it to NULL, the program crashes too. I've already put this member as private, protected and public. In all cases the problem is the same.
Thanks for the attention of all! Hope u can help me with this headache.
Thales Medeiros.