Advertisement

Can someone tell what I'm doing wrong!!!!

Started by December 22, 2001 11:17 AM
2 comments, last by Kelson 22 years, 11 months ago
Yeah, yeah, stupid annoyning newbie ect. Anyway, I''m trying to learn DDraw 7 but I keep getting a primary surface create error. umm... Here''s the code. Not all of it, obviously, but just the init part. void Init(HINSTANCE hInstance, int nCmdShow) { WNDCLASS wc; DDSURFACEDESC2 ddsd; HRESULT hRet; DDSCAPS2 ddscaps; //Create and initialize the window class wc.style = CS_HREDRAW | CS_VREDRAW; wc.cbClsExtra = 0; wc.cbWndExtra = sizeof(DWORD); wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "NewWindow"; //Get dimensions of display int ScreenWidth = GetSystemMetrics(SM_CXSCREEN); int ScreenHeight = GetSystemMetrics(SM_CYSCREEN); //Create and display window HWND hWnd; hWnd = CreateWindow("NewWindow", "Space Invaders Ripoff", WS_VISIBLE|WS_POPUP, 0, 0, ScreenWidth, ScreenHeight, NULL, NULL, hInstance, NULL); ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); //Create the DirectDraw object hRet=DirectDrawCreateEx(NULL,(VOID**)&lpDD, IID_IDirectDraw7, NULL); if (hRet!=DD_OK) { MessageBox(hWnd, "DDraw Create error", "error!", MB_ICONERROR); } //Set Cooperative Level to full screen lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT); if (hRet!=DD_OK) { MessageBox(hWnd, "coop level error!!!", "error!", MB_ICONERROR); } //Set the display mode hRet=lpDD->SetDisplayMode( 640, 480, 16, 0, 0); if (hRet!=DD_OK) { MessageBox(hWnd, "set display mode error", "error!", MB_ICONERROR); } //Create the clipper hRet=lpDD->CreateClipper(0 ,&lpClip,NULL); if (hRet!=DD_OK) { MessageBox(hWnd, "Clip Create error", "error!", MB_ICONERROR); } //Create the Primary surface ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddsd.dwWidth = 640; ddsd.dwHeight = 480; hRet=lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); if (hRet!=DD_OK) { MessageBox(hWnd, "Primary Create error", "error!", MB_ICONERROR); } if (hRet=DDERR_INVALIDOBJECT) { MessageBox(hWnd, "invalid object", "error type!", MB_ICONERROR); } if (hRet=DDERR_INVALIDCAPS) { MessageBox(hWnd, "invalid caps", "error type!", MB_ICONERROR); } if (hRet=DDERR_UNSUPPORTEDMODE) { MessageBox(hWnd, "unsupported mode", "error type!", MB_ICONERROR); } if (hRet=DDERR_INVALIDPARAMS) { MessageBox(hWnd, "invalid params", "error type!", MB_ICONERROR); } //Get the back buffer lpDDSPrimary->GetAttachedSurface( &ddscaps, &lpDDSBack); //Set the clipper to the primary surface lpDDSPrimary->SetClipper(lpClip); //flag init as completed bInit = TRUE; } I''ve looked over my books, tutorials, and such but I can''t seem to find the problem! *waahh!* I''ve tried everything except for what works... Nooooooo!!!!!!!!! no flames!!!!!!!!!!!
/////////////////////////////////////////////////"Sufficiently advanced technology is indistinguishable from magic" Arthur C. Clark
why dont you post the error that you are getting? (ie the saying that the create fails means nothing really unless you look thet error code that CreateSurface() is returning).
Advertisement
Well... all of those that are checked in the code. but I assumed that if it''s an invalid object that it would cause everything else to go wrong too... right??
/////////////////////////////////////////////////"Sufficiently advanced technology is indistinguishable from magic" Arthur C. Clark
seems like you are forgetting wc.lpfnWndProc, and you're not registering the windowclass...

Edited by - kvh on December 25, 2001 9:13:37 AM

This topic is closed to new replies.

Advertisement