I see a definite problem here

BITMAP BitMap;

Variable is declared but not initialized

temp.GetBitmap(&BitMap);

GetBitmap should not work to the variable which is not initilaized

oldBmp = mem.SelectObject(&temp);

Obvious reason is it should fail

On some systems the garbage for BitMap may not be NULL.