Perhaps this is a stupid question, I don’t understand why I can’t get the DC created in the following code:
HBITMAP COcrDlg::LoadClippedBitmap(LPCTSTR pathName,UINT maxWidth,UINT maxHeight)
{
HBITMAP hBmp = (HBITMAP)::LoadImage(NULL, pathName, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if (!hBmp)
return NULL;
HDC hdc = (HDC)GetDC();
HDC hdcMem = CreateCompatibleDC(hdc);
if (!hdcMem)
{
DWORD err = GetLastError();
}
...
...
...
The hBmp bitmap loads fine, and the hdc value has a valid value. But calling CreateCompatibleDC () returns a NULL pointer. Then GetLastError () returns 0! Can anyone guess what is going on here, please?
PS: There are no memory allocations or GDI routines before this ... therefore I believe that memory leaks should be eliminated.
source
share