Skip to main content
gamedev.net
🔒 Locked

Direct Draw Initilization....

Started by 1kevgriff 6 replies 700+ views
Original Post
1kevgriff
1kevgriff
Here is the problem, I''ve been trying for hours to get this code to work, but I keep getting an error. Here is the DirectDraw Initilization code:
  
// Attempt to create a Direct Draw interface

	if ((DirectDrawCreateEx(NULL, (void **) &lpDD, IID_IDirectDraw7, NULL)) != DD_OK) 
	{
		MessageBox(NULL, "Create Error", "ERROR", MB_OK);
		return false;
	}
	// Attempt to take full control of the system

	if ((lpDD->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE)) != DD_OK) 
	{
		MessageBox(NULL, "Co-Op Error", "ERROR", MB_OK);
		return false;
	}
	// Attempt to change the screen resolution

	if ((lpDD->SetDisplayMode(800, 600, 16, 0, 0)) !=DD_OK) 
	{
		MessageBox(NULL, "Display Error", "ERROR", MB_OK);
		return false;
	}
	
	// Prepare to create the primary Direct Draw surface

	DDSURFACEDESC2 ddsd;
	ZeroMemory(&ddsd, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags =	DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
    ddsd.ddsCaps.dwCaps =	DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | 
		DDSCAPS_3DDEVICE | DDSCAPS_COMPLEX;
    ddsd.dwBackBufferCount = 1;
	
	
	// Attempt to create the primary Direct Draw surface

	if ((lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL)) != DD_OK) 
	{
		MessageBox(NULL, "Surface Error", "ERROR", MB_OK);
		return false;
	}
	
	// Prepare to retrieve the back buffer surface

	DDSCAPS2 ddscaps;
	ZeroMemory(&ddscaps, sizeof(ddscaps));
	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	
	// Attempt to retrieve the back buffer surface

	if ((lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBackBuffer)) != DD_OK) 
	{
		MessageBox(NULL, "Get Surface Error", "ERROR", MB_OK);
		return false;
	}

  
I get the "Co-Op Error", and I can''t figure out why? I tried setting it to normal, but then I get the "Surface Error". Thanks alot.
Quantum
Quantum
can''t see anything wrong with the code..
Check the return value, it can be one of the following values:
DDERR_EXCLUSIVEMODEALREADYSET
DDERR_HWNDALREADYSET
DDERR_HWNDSUBCLASSED
DDERR_INVALIDOBJECT
DDERR_INVALIDPARAMS
DDERR_OUTOFMEMORY
Peon
Peon
Not sure, but I need to QueryInterface() when I initialize... I think that''s for a different version of DirectX though
Peon
wazoo69
wazoo69
Coaster Kev....are you SURE you''re passing it a VALID window handle?? I''ve had many problems in the past, only to discover my
window handle was crapola...

the easiest way is a:

if(hwnd == NULL){
MessageBox(NULL, "Beefcake! Beeeefcake!", "ERROR", MB_OK);
return FALSE;
}

Otherwise, your code looks okay..

Wazoo
1kevgriff
1kevgriff
Wazoo, you were right. My window handle had nothing in it. Now I''m confused. How do I fill it or what do I fill it with? At least I know what the problem is...
wazoo69
wazoo69
hurrah! I''m actually right!

Well Coaster Kev...in all windows platform programs, you MUST create a window handle which you can then use in your DirectX stuff...BUT before you can create a window handle you must first
register your class with Windows..

//try this..
WNDCLASS winClass;
HWND hwnd;

winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance; //our instance handle
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION)
winclass.hCursor = LoadCursor(NULL, IDC_ARROW)
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH)
winclass.lpszMenuName = NULL
winclass.lpszClassName = "Project1"

//attempt to register it
if(!RegisterClass(&winclass))
return(0);

//create our window handle HERE!
hwnd = CreateWindow("Project1",
"Game 1",
WS_OVERLAPPEDWINDOW,
0,0,
800,600,
GetDesktopWindow(),
NULL,
winclass.hInstance,
NULL);
if(hwnd == NULL)
//error creating main window handle
return(0);


//NOW our hwnd contains our window handle to this application!

That should be more than enough to help you out...

Wazoo

1kevgriff
1kevgriff
Duh! How could I''ve been so stupid? Maybe it was the hours of work. Thanks for refreshing my memory!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.