Solved

CreateSuface failing

Posted on 1997-06-30
5
272 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
ID: 1399697
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
ID: 1399698
Doesn't make a difference.
0
 
LVL 3

Expert Comment

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

Author Comment

by:guzza
ID: 1399700
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
ID: 1399701
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

776 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