Archived

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

DirectDraw Loading Image problem..

This topic is 5532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have come to implement a tile system in my program, and I read through and array and load my tiles etc, loading a tile consists of
  
cTile * SpawnTile(LPSTR lpFileName, cGraphics *gfx)
{
	cTile	*tmp;

	tmp = new cTile(gfx);

	tmp->SetSurface(lpFileName);

	tmp->SetPos(0,0);
	tmp->SetLoaded(true);

	return(tmp);
}
  
this fails and my program stops, however if I comment out SetSurface(lpFilename) it works.. so I go deeper and SetSurface calls LoadBMPSurface ..
  
LPDIRECTDRAWSURFACE7 cGraphics::LoadBMPSurface(LPCSTR lpFilename)
{
	HDC						hDC;
	HBITMAP					bit;
	BITMAP					bitmap;
	LPDIRECTDRAWSURFACE7	surf;

	bit = (HBITMAP) LoadImage(NULL,lpFilename,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADFROMFILE);

	if(!bit)
	{
		return(NULL); //Error trapping

	}

	if(GetObject(bit,sizeof(BITMAP),&bitmap) == NULL)
	{
		return(NULL);
	}

	surf = CreateNewSurface(bitmap.bmWidth,bitmap.bmHeight);

	if(surf == NULL)
	{
		logFile << "Failed to create surface";
		DeleteObject(bit);
		return(NULL); //More error trapping

	}
	else
	{
		surf->GetDC(&hDC);

		HDC bit_dc = CreateCompatibleDC(hDC);

		//Blit the interface to the surface


		SelectObject(bit_dc,bit);
			
		BitBlt(hDC,0,0,bitmap.bmWidth,bitmap.bmHeight,bit_dc,0,0,SRCCOPY);

		surf->ReleaseDC(hDC);

		DeleteDC(bit_dc);
	}

	DeleteObject(bit);

	return(surf);
}
  
Now I know the bitmap loading routine works because I can make a surface object using the graphics component and it works fine. And I have put logging in and it doesn''t fail at the LoadImage .. it just fails.. What I am asking is, am I missing something really stupid? Is there something I should be seeing that I am not. Hammerstein PS - The image is definatley named right, and definatley in the right place (I can manually load the image) =*= If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore =*=

Share this post


Link to post
Share on other sites