Solved

CreateSuface failing

Posted on 1997-06-30
5
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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 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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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