can't load .bmp

Started by
2 comments, last by yq 22 years, 10 months ago
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
Advertisement
is the surface created?
Yes. I''ve tried it with multiple surfaces and I get the same error.
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

This topic is closed to new replies.

Advertisement