I have the following C++ line that obtains the GDI+ handle out of GDI's device context:
//HDC hDC = device context from GDI
if(hDC)
{
//Obtain graphics handle for GDI++
Graphics* pgrpx = new Graphics(hDC); //I get invalid memory exception here
//Code continues
//...
//Free object
delete pgrpx;
pgrpx = NULL;
}
It works just fine in my tests.
But recently I received a crash dump for the app, with the "thread referenced memory location that it has no access to" exception at the line I pointed above in the code -- right where the Graphics object is supposed to be initialized.
What could be the issue here? And how to address it?