Which kind of memory problem occurs (is there an error message)?
Some notes:
- The
SelectObject
parameter is a pointer to an object - The bitmap must be delesected before it is destroyed (by the destructor)
- You may check the return values to detect errors immediately when they occur
So change the code to (using debug macros to detect errors and calling CDC::GetPixel):
COLORREF Myfunction(CPoint p)
{
CBitmap bmpCOM;
VERIFY(bmpCOM.LoadBitmap(IDB_BMP2));
CDC dcCOM;
VERIFY(dcCOM.CreateCompatibleDC(NULL));
CBitmap *pOldBm = dcCOM.SelectObject(&bmpCOM);
ASSERT(pOldBm);
COLORREF clr = dcCOM.GetPixel(p);
ASSERT(clr != (COLORRREF)-1);
dcCom.SelectObject(pOldPm);
return clr;
}