Solved

CreateSuface failing

Posted on 1997-06-30
5
269 Views
Last Modified: 2013-12-03
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
0
Comment
Question by:guzza
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:byang
Comment Utility
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
0
 

Author Comment

by:guzza
Comment Utility
Doesn't make a difference.
0
 
LVL 3

Expert Comment

by:byang
Comment Utility
Just add more flags. Don't expect CreateSurface to automatically creates a surface matching the current screen mode.
0
 

Author Comment

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

0
 
LVL 1

Accepted Solution

by:
YamSeng earned 150 total points
Comment Utility
There are several possibilities:
1) Use the ddscaps editor provided with dx to check whether the resolution you want is supported. If it's not it will not return a dd_ok.

2) Are u using the directx headers compiled for the cygnus gnu compiler? if u're not u may run into problems

I'm using DX5, my createsurface function requires only 3 parameters.  
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video discusses moving either the default database or any database to a new volume.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now