Archived

This topic is now archived and is closed to further replies.

yq

can't load .bmp

Recommended Posts

This one is driving me crazy. Here is my bitmap loader.
  int LoadBitmapFile(char *filename, LPDIRECTDRAWSURFACE surface)
{
	HDC sourcedc;
	HDC destdc;
	HBITMAP hbitmap;
	BITMAP bmp;
	int height,width;
	
	hbitmap = (HBITMAP)LoadImage(NULL,filename,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION | LR_LOADFROMFILE);
	sourcedc =CreateCompatibleDC(NULL);
	SelectObject(sourcedc,hbitmap);
	GetObject(hbitmap,sizeof(BITMAP),&bmp);
	width = bmp.bmWidth;
	height = bmp.bmHeight;
	surface->GetDC(&destdc);
	BitBlt(destdc,0,0,width,height,sourcedc,0,0,SRCCOPY);
	surface->ReleaseDC(destdc);
	DeleteDC(destdc);

	return(0);
}  
When I run it through the debugger I get DDraw:ERROR:Could not obtain DC DDraw:ERROR:No DC allocated Edited by - yq on June 21, 2001 11:22:19 PM

Share this post


Link to post
Share on other sites
change this:
surface->GetDC(&destdc);

to this:
surface->GetDC(destdc);

You are passing an HDC, which is a handle to a Device Context, which means the dereferencing (is that the correct word?) has been done for you.

Cheers

Share this post


Link to post
Share on other sites