Archived

This topic is now archived and is closed to further replies.

Keep Getting a DERR_INVALIDCAPS

This topic is 6364 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, all When ever I call CreateSurface i get a DERR_INVALIDCAPS. This is the code I put: ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); I don't understand what im doing wrong, well ill include the whole program without the windows stuff and most of the error checking code, so that someone can help me. Code......................... LPDIRECTDRAW7 lpDD; LPDIRECTDRAWSURFACE7 lpDDSPrimary; // DirectDraw primary surface LPDIRECTDRAWSURFACE7 lpDDSBack; LPDIRECTDRAWSURFACE7 lpDDSOffOne = NULL; HWND hwnd; long xpos = 0; long ypos = 0; static void ReleaseObjects( void ) { if ( lpDD != NULL ) { if ( lpDDSPrimary != NULL ) { if( lpDDSOffOne !=NULL ) { lpDDSOffOne->Release(); lpDDSOffOne = NULL; } lpDDSPrimary->Release(); lpDDSPrimary = NULL; } lpDD->Release(); lpDD = NULL; } } int GameInit() { DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; HRESULT ddrval; RECT srcRect; RECT destRect; // Create the DirectDraw object -- we just need an IDirectDraw // interface so we won't bother to query an IDirectDraw2 if(FAILED(DirectDrawCreateEx(NULL, (void**)&lpDD, IID_IDirectDraw7, NULL))) { MessageBox(hwnd, "1", "", MB_OK); } if(FAILED(lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN))) { MessageBox(hwnd, "2", "", MB_OK); } if(FAILED(lpDD->SetDisplayMode(640, 480, 8, 0, 0))) { MessageBox(hwnd, "3", "", MB_OK); } // Create the primary surface with one back buffer. ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); if(ddrval == DD_OK) { MessageBox(hwnd, "4", "", MB_OK); } // I usally have some error checking code here, but its to long. ddscaps.dwCaps = DDSCAPS_BACKBUFFER; if(FAILED(lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack))) { MessageBox(hwnd, "9", "", MB_OK); } ZeroMemory( &ddsd, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); MessageBox(hwnd, "10", "", MB_OK); ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_CKSRCBLT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwHeight = 100; ddsd.dwWidth = 100; ddsd.ddckCKSrcBlt.dwColorSpaceLowValue = RGB(65,40,254); MessageBox(hwnd, "11", "", MB_OK); if(FAILED( lpDD->CreateSurface(&ddsd, &lpDDSOffOne, NULL))) { MessageBox(hwnd, "5", "", MB_OK); } lpDDSOffOne = DDLoadBitmap(lpDD, "ship1.bmp", 0, 0); MessageBox(hwnd, "41", "", MB_OK); return 0; } int GameMain() { DDSURFACEDESC ddsd; RECT srcRect; RECT destRect; HRESULT ddrval; xpos += 5; ypos += 3; if( (ypos + 50) == 480) { ypos = 0; } if( (xpos + 50) == 640) { xpos = 0; } srcRect.top = 0; srcRect.left = 0; srcRect.right = 50; srcRect.bottom = 50; MessageBox(hwnd, "51", "", MB_OK); ddrval = lpDDSBack->BltFast( xpos, ypos, lpDDSOffOne, &srcRect, DDBLTFAST_DESTCOLORKEY ); if(ddrval != DD_OK) { MessageBox(hwnd, "15", "", MB_OK); } while(1) { MessageBox(hwnd, "34", "", MB_OK); ddrval = lpDDSPrimary->Flip(NULL, 0); if(ddrval == DD_OK) { MessageBox(hwnd, "56", "", MB_OK); break; } if(ddrval == DDERR_SURFACELOST) { MessageBox(hwnd, "60", "", MB_OK); ddrval = lpDDSPrimary->Restore(); if(ddrval != DD_OK) { break; } } MessageBox(hwnd, "30", "", MB_OK); return 0; } int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; lpCmdLine = lpCmdLine; hPrevInstance = hPrevInstance; if ( !doInit( hInstance, nCmdShow ) ) { return FALSE; } GameInit(); while ( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); GameMain(); } ReleaseObjects(); return msg.wParam; } Well if anyone could help, I would like that, Thanks... James, age 15, Later.. Edited by - JSCFaith on 7/14/00 2:14:59 AM

Share this post


Link to post
Share on other sites
Just off the bat I saw you didn''t clear the memory of the Direct Draw surface description 2 struct before using it.

throw in
ZeroMemory(&ddsd, sizeof(ddsd));
before
ddsd.dwSize = sizeof(ddsd);
in your problematic code.

Also, I''m not positive, but the display mode of 8bbp might give you problems too, I haven''t worked with 8bpp display mode in a while and I can''t remember when exactly you create or attach the palette, but you don''t seem to have that anywhere yet.

Share this post


Link to post
Share on other sites