Advertisement

Direct Draw 7 initializing problem

Started by July 27, 2000 12:31 PM
3 comments, last by dron1 24 years, 5 months ago
I am trying to make an engine. I just started and I am already having problems. Anyway my question is what does this debug error mean? heres my source
        
CEngine::CEngine()
{
	file.open("log2.txt", ios::out);
	DD_Already_Init = 0;
}

HRESULT CEngine::Direct_Draw_Init(int height_, int width_, int bpp_, int windowed_, HWND hwnd_)
{
	height = height_;
	width = width_;
	bpp = bpp_;
	windowed = windowed_;
	hwnd = hwnd_;

	if (DD_Already_Init)
	{
		return DDERR_DIRECTDRAWALREADYCREATED;
	}
	file << "1" << endl;
	
	//create the DD object; a direect draw 7 interface, hehehehehe
	if (FAILED(hr = DirectDrawCreate(NULL, &lpdd, NULL)))
	{
		return hr;
	}
	file << "2" << endl;

	
	
	if (FAILED(lpdd->QueryInterface(IID_IDirectDraw, (LPVOID *)&lpdd7)))
	{
		lpdd->Release();
		lpdd = NULL;
		return 1981;
	}
	file << "3" << endl;

	//coop level

	switch (windowed_)
	{
	//Full screen

	case 0:
		if (FAILED(hr = lpdd7->SetCooperativeLevel(hwnd, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | 
													DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
		{
			return hr;
		}
		break;
	//windowed

	case 1:
		if (FAILED(hr = lpdd7->SetCooperativeLevel(hwnd, DDSCL_NORMAL)))
		{
			return hr;
		}
		break;
	//default is full screen

	default:
		if (FAILED(hr = lpdd7->SetCooperativeLevel(hwnd, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | 
													DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
		{
			return hr;
		}
		break;
	}
	file << "4" << endl;

	if (FAILED(lpdd7->SetDisplayMode(800, 600, 8, 0, 0)))
	{
		return hr;
	}
	file << "5" << endl;

	//set flag

	DD_Already_Init = 1;
	return 1;
}

int CEngine::Direct_Draw_Shutdown()
{
	//if lppd7 exist release it

	if (lpdd7!=NULL)
		lpdd7->Release();
	file.close();
	return 1;
}

CEngine::CEngine(int height_, int width_, int bpp_, int windowed_, HWND hwnd_)
{
	Direct_Draw_Init(height_, width_, bpp_, windowed_, hwnd_);
}

CEngine::~CEngine()
{
	Direct_Draw_Shutdown();
}
        
i do have lpdd and lpdd7 declared. thanks in advance. Edited by - dron1 on 7/27/00 12:34:23 PM
That''s quite an object model you have there! I usually prefer the good ''ol CEngine::DoEverythingForMeInOneBigFunction() myself!

The ESP to which the dialog box refers is the Stack Pointer. It is a register in the x86 CPU and it points to the call stack. Note that the call stack holds the parameters in a function call. If your stack is corrupt it could be because a function pointer is NULL.

The dialog box also tells you to check your calling conventions.
A calling convention (e.g. __stdcall, __fastcall, __cdecl, and thiscall) determine how the compiler sets up and cleans up the call stack durring a function call. thiscall is the convention for class member functions, otherwise all your code will default to __cdecl.

To debug this code, forget about writing numbers to a file, use your debugger and set break points. Then step though your code one line at a time. You do know what a debugger is don''t you? Don''t you know how to use one? Man I must be really bored to reply to this kind of post.
Advertisement
I just noticed something else. You only have this line
    file.open("log2.txt", ios::out);    

in the default constructor. You need to open the file before you write to it and your other constructor is calling Direct_Draw_Init before the file is open.
Thank you for your replies. Thank you for finding another bug.
    if (FAILED(lpdd->QueryInterface(IID_IDirectDraw, (LPVOID *)&lpdd7)))	{		lpdd->Release();		lpdd = NULL;		return 1981;	}    


There''s another problem here. Qhy are you querying the interface while sending a IID_IDirectDraw GUID, when it should be a IID_IDirectDraw7? Hope this helps solve your problem.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.

This topic is closed to new replies.

Advertisement