Link to home
Start Free TrialLog in
Avatar of guzza
guzza

asked on

CreateSuface failing

Will somebody please tell me what's wrong with this. CreateSurface is
returning DDERR_INVALIDPARAMS. I'm trying to create a single surface to
display a picture. I'm using the Cygnus GNU-Win32 compiler (beta 18) and
need the code to be in C. I've looked at all the sample code I can find
and can't figure out what's wrong.

LPDIRECTDRAWSURFACE lpDDSPrimary;  
LPDIRECTDRAW lpDD;
HRESULT ddrval;
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
.
.
ddrval = DirectDrawCreate(NULL,&lpDD,NULL);
ddrval = lpDD->lpVtbl->SetCooperativeLevel(lpDD,hWnd,DDSCL_EXCLUSIVE |
DDSCL_FULLSCREEN);
ddrval = lpDD->lpVtbl->SetDisplayMode(lpDD,640,480,8);

memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
ddrval = lpDD->lpVtbl->CreateSurface(lpDD,&ddsd,&lpDDSPrimary,NULL);
if (ddrval != DD_OK)
 {
 lpDD->lpVtbl->Release(lpDD);
 return FALSE;
 }

Thanks in advance...

Nick Gallimore
Avatar of byang
byang
Flag of United States of America image

Your code is too minimalistic. You also need to specify DDSD_HEIGHT|DDSD_WIDTH for dwFlags, and set dwWidth and dwHeight:

ddrval = lpDD->lpVtbl->SetDisplayMode(lpDD,640,480,8);

memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
ddsd.dwHeight=480; ddsd.dwWidth=640;
ddsd.ddsCaps.dwCaps = DDSC
Avatar of guzza
guzza

ASKER

Doesn't make a difference.
Just add more flags. Don't expect CreateSurface to automatically creates a surface matching the current screen mode.
Avatar of guzza

ASKER

Any ideas/suggestions as to which ones to try? I tried adding DDSD_BACKBUFFERCOUNT,  DDSD_ALPHABITDEPTH and DDSD_PIXELFORMAT, but nothing changed.

ASKER CERTIFIED SOLUTION
Avatar of YamSeng
YamSeng

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial