problem selecting a bitmap into printer DC

hlin_do's Avatar, Join Date: Feb 2007
Newbie Member
I have a problem to SelectObject of Bitmap into memery DC. My code is like,
Code:
HINSTANCE hinstOriginal;
hinstOriginal = ::AfxGetResourceHandle();
::AfxSetResourceHandle(g_hResInstance);

CDC mem;
CBitmap *oldBmp;
CBitmap temp;
BOOL B = temp.LoadBitmap(id);   //id is resource id 
BITMAP BitMap;
temp.GetBitmap(&BitMap);

mem.CreateCompatibleDC( pPrintDC );             // a printer DC
mem.SetMapMode (pPrintDC->GetMapMode ());

oldBmp = mem.SelectObject(&temp);       // this call returns 0 on some PCs! 

CPoint size;
size.x = BitMap.bmWidth;
size.y = BitMap.bmHeight;
mem.DPtoLP(&size);

BOOL bret = pGDoc->m_pDC->StretchBlt(m_iX,
                m_iY*-1,
                m_iWidth,
                m_iHeight*-1, 
                &mem,
                0,
                0,
                size.x,
                size.y,
                SRCCOPY);
This code works on same PC, but not on others, SelectObject returns 0;
Please help.

Thank you very much.

hlin_do

henryzlin@hotmail.com

Last edited by shabbir; 10Feb2007 at 09:40.. Reason: Code formating.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Check out the error code with the GetLastError.
hlin_do's Avatar, Join Date: Feb 2007
Newbie Member
GetLastError returns 0 befaore and after SelectObject call

hlin_do
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
hlin_do's Avatar, Join Date: Feb 2007
Newbie Member
I think I know how to make it work now. Basicly, I need to load as DIB instead bitmap.

Thanks anyway!

hlin_do