🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Problem with the DDLoadBitmap.... please help.

Started by
-1 comments, last by GameDev.net 24 years, 7 months ago
The probram crashes when I´m trying to Load a image into the lpDDSBackground surface. I have no idea why... please help.

Here is some of the source:

//#if defined( __BORLANDC__ ) && defined( __WIN32__ )
//#define _WIN32
//#endif

#include
#include
#include
#include
#include
#include

#define screen_rel_x 1024
#define screen_rel_y 768
#define screen_bit 16


LPDIRECTDRAW lpDD;
LPDIRECTDRAWSURFACE lpDDSPrimary;
LPDIRECTDRAWSURFACE lpDDSBack;
LPDIRECTDRAWSURFACE lpDDSBackground;

........
..........
........
........
........

IDirectDrawSurface *DDLoadBitmap(IDirectDraw *pdd, LPCSTR szBitmap, int dx, int dy)
{
HBITMAP hbm;
BITMAP bm;
IDirectDrawSurface *pdds;
DDSURFACEDESC ddsd;

hbm = (HBITMAP)LoadImage(GetModuleHandle (NULL),szBitmap, IMAGE_BITMAP,dx,dy, LR_CREATEDIBSECTION);
if(hbm==NULL)
hbm=(HBITMAP)LoadImage(GetModuleHandle(NULL),szBitmap, IMAGE_BITMAP,dx,dy, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hbm==NULL)
return(NULL);
GetObject(hbm,sizeof(bm),&bm);
ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
// if(pdd->CreateSurface(&ddsd,&pdds, NULL) != DD_OK)
// return(NULL);
DDCopyBitmap(pdds, hbm, 0,0,0,0);
DeleteObject(hbm);
return(pdds);
}


HRESULT DDCopyBitmap(IDirectDrawSurface *pdds, HBITMAP hbm, int x, int y, int dx, int dy)
{
HDC hdcImage, hdc;
BITMAP bm;
DDSURFACEDESC ddsd;
HRESULT hr;

if(hbm==NULL|pdds==NULL)
return E_FAIL;
hdcImage = CreateCompatibleDC(NULL);
SelectObject(hdcImage,hbm);
GetObject(hbm, sizeof(bm), &bm);
dx = dx == 0 ? bm.bmWidth :dx;
dy = dy == 0 ? bm.bmHeight :dy;
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
pdds->GetSurfaceDesc(&ddsd);
if((hr = pdds->GetDC(&hdc)) == DD_OK)
{
StretchBlt(hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight,hdcImage, x, y, dx, dy, SRCCOPY);
pdds->ReleaseDC(hdc);
}
DeleteDC(hdcImage);
return hr;
}


bool LoadGameData(void)
{
HRESULT hr;
HDC dc;

hr = lpDDSPrimary->GetDC(&dc);
SetTextColor(dc,RGB(255,255,255));
SetBkColor(dc,RGB(0,0,0));
TextOut(dc,screen_rel_x / 3+70, screen_rel_y-20,"Loding game data, please wait...",32);
lpDDSPrimary->ReleaseDC(dc);
lpDDSBackground = DDLoadBitmap(lpDD, "BACK.BMP", 1024, 768); //<--Crashes here
if(lpDDSBackground == NULL)
PostQuitMessage(0);
return(true);
}


I´m writing in Borland C++ 5.0 if that´s why it dosn´t work. I have include some directdraw libs´s made for Borland C++.

//Thanks for all help....

This topic is closed to new replies.

Advertisement