need help with problem... (maybe typecasting)

Started by
5 comments, last by bony 20 years, 3 months ago
i have a problem compiling a basic program, that just initializes directdraw 7. the problems are marked in the code:
// directdrawer.cpp -> direct draw engine

// a1.0 - 05.01.2004

#define WIN32_LEAN_AND_MEAN		// MFC-includes are being cut for faster compiling

#define INITGUID				// include all GUIDs 


#include <windows.h>
#include <windowsx.h>
#include <stdio.h>

#include <ddraw.h>
#include "directdrawer.h"

// EXTERNALS ///////////////////////////////////////////////////////

/*extern HWND			hwnd_main;			// THESE MUST BE GLOBALS IN THE MAIN SOURCE FILE
extern HINSTANCE	hinstance_main;		// AND HOLD THE MAIN APP INSTANCE AND WINDOW HANDLE
*/
// GLOBALS /////////////////////////////////////////////////////////

LPDIRECTDRAW7	lpdd		= NULL;		//pointer for DirectDraw interface 7



// FUNCTIONS ///////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////


// CREATEDIRECTDRAWER //////////////////////////////////////////////

int CreateDirectDrawer(void)
{
	// initialize COM

	if(FAILED(CoInitialize(NULL)))
	{	MessageBox(NULL, "CoInitialize() FAILED", "ERROR - directdrawer.cpp", MB_OK);
		return(1);	}
	
	// get DirectDraw interface 7

	if(FAILED(CoCreateInstance(CLSID_DirectDraw,
								NULL,
								CLSCTX_ALL,
								IID_IDirectDraw7,	////////////////////////////////////////////////////////////////

								(LPVOID*)&lpdd)))	//if i don''t cast this (in the "tricks..."-book it is not casted),

											//then i get a typecasting error.

											//but... (look further down)

											////////////////////////////////////////////////////////////////

	{	MessageBox(NULL, "CoCreateInstance() for Direct Draw 7 FAILED", "ERROR - directdrawer.cpp", MB_OK);
		return(2);	}

	// initialize the interface

	if(FAILED(lpdd->Initialize(NULL)))
	{	MessageBox(NULL, "IDirectDraw7_Initialize() FAILED", "ERROR - directdrawer.cpp", MB_OK);
		return(3);	}

	//uninitialize COM

	CoUninitialize();

	return(0);
}//end: CreateDirectDrawer()


// SETCOOP /////////////////////////////////////////////////////////

int SetCoop(HWND hwnd, BOOL fullscreen)
{
	if(fullscreen)			//test if user requested fullscreen cooperative mode

	{
		//set cooperative level

		if(FAILED(lpdd->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN	|
												  DDSCL_EXCLUSIVE	|
												  DDSCL_ALLOWMODEX	|
												  DDSCL_ALLOWREBOOT)))
		{	MessageBox(NULL, "SetCooperativeLevel() FAILED", "ERROR - directdrawer.cpp", MB_OK);
			return(1);	}
	}
	else
	{
		//set cooperative level										//////////////////////////////////////////////////////////////////////////

		if(FAILED(lpdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL)))					//during runtime is get an acces violation here, the error code is CXX0030

		{	MessageBox(NULL, "SetCooperativeLevel() FAILED", "ERROR - directdrawer.cpp", MB_OK);	//the error is somehow caused by lpdd. i think it is related to the typecast above...

			return(1);	}									//////////////////////////////////////////////////////////////////////////

	}

	return(0);
}//end: SetCoop(...)


// CLEANUPDRAWER

int CleanupDrawer(void)
{
	if(lpdd)
	{	lpdd->Release();
		lpdd = NULL;	}

	//TODO: release all other stuff that will be added.


	return(0);
}
her are directdrawer.h and the main source file, if you want to compile it yourself:
//directdrawer.h -> header für directdrawer.cpp - direct draw engine

//a1.0


#ifndef DRAWER_H
#define DRAWER_H

#include <ddraw.h>

// EXTERNALS ///////////////////////////////////////////////////////

extern LPDIRECTDRAW7	lpdd;		//pointer for DirectDraw interface 7

 
// PROTOTYPES //////////////////////////////////////////////////////

int CreateDirectDrawer(void);
int SetCoop(HWND hwnd, BOOL fullscreen);
int CleanupDrawer(void);

#endif
// emptyprog.cpp - leeres windows programmgeruest (oeffnet fenster)


#define WIN32_LEAN_AND_MEAN		// MFC-includes are being cut for faster compiling


// INCLUDES ////////////////////////////////////////////////////////

#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <ddraw.h>
#include "directdrawer.h"

// GLOBALS /////////////////////////////////////////////////////////

HWND		hwnd_main		= NULL;	//global window handle

HINSTANCE	hinstance_main	= NULL;	//global application instance

extern LPDIRECTDRAW7	lpdd;		//pointer for DirectDraw interface 7


// PROTOTYPES //////////////////////////////////////////////////////


// WINPROC /////////////////////////////////////////////////////////

LRESULT CALLBACK WindowProc(HWND	hwnd,
							UINT	msg,
							WPARAM	wparam,
							LPARAM	lparam)
{
	PAINTSTRUCT	ps;		//can be used in WM_PAINT

	HDC			hdc;	//handle to a device context - "


	//check message

	switch(msg)
	{
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd, &ps);
			//do the painting here

			EndPaint(hwnd,&ps);

			return(0);
		}break;
	case WM_DESTROY:
		{
			PostQuitMessage(NULL);
		}

		default:break;

	}//end: switch(msg)


	return(DefWindowProc(hwnd, msg, wparam, lparam));	//process any message that i didn''t mention

}//end: WindowProc(...)


// WINMAIN /////////////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE	hinstance,
				   HINSTANCE	hprevinstance,
				   LPSTR		lpcmdline,
				   int			ncmdshow)
{
	WNDCLASSEX	winclass;	//windows class

	HWND		hwnd;
	MSG			msg;		//msg for the WinProc


	BOOL		exit_loop	= FALSE;	//for main event loop


	//fill in class data

	winclass.cbSize			= sizeof(winclass);
	winclass.style			= CS_DBLCLKS | CS_OWNDC | // (no "close" button -> //CS_NOCLOSE |

							  CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= WindowProc;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hinstance;
	winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
	winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.lpszMenuName	= NULL;
	winclass.lpszClassName	= "
WINCLASS"; winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); hinstance_main = hinstance; if(!RegisterClassEx(&winclass)) //register the class return(MessageBox(NULL, "could not register WNDCLASSEX winclass\nRegisterClassEx() failed", "ERROR", MB_OK)); if(!(hwnd = CreateWindowEx(NULL, //extended style "WINCLASS", //clss "fill in program title", //window title WS_OVERLAPPEDWINDOW | WS_VISIBLE, //style 0,0, //x,y position 400,400, //width,height NULL, //handle to parent window NULL, //handle to menu hinstance, //application instance NULL))) //extra creation parameters return(MessageBox(NULL, "could not create window\nCreateWindowEx() failed", "ERROR", MB_OK)); hwnd_main = hwnd; CreateDirectDrawer(); SetCoop(hwnd, FALSE); // MAIN EVENT LOOP // while(!exit_loop) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) //test for message in queue { if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } //TODO: main game processing }//end: while(!exit_loop) CleanupDrawer(); return(msg.wParam); }//end: WinMain(...) thanks for taking a look! bony if you found any spelling errors, you may keep them.
:) if you found any spelling errors, you may keep them. :)
Advertisement
No one is going to look through all that code. Post the error messages you get upon compiling and we''ll be able to help you out a lot quicker.

James
you don't have to look through the entire code - i marked the important parts with comments. i posted the whole code, in case someone might want to compile it themself...

the error code i get during debugging is CXX0030 .

look at the two comments in the first sourcefile, please. (scroll to the very right to see them)

thank you

[edited by - bony on January 6, 2004 11:37:43 AM]
:) if you found any spelling errors, you may keep them. :)
First just a small note, it's not a compiling error, but a runtime error.

First thing to check is are you running the directx debug runtime. If you are then the debug output spew should give you some more clue as to your problem.

Edit: does it give you the same result if the fullscreen flag is set?

[edited by - jamessharpe on January 6, 2004 11:43:59 AM]
actually i don''t even know what the directx debug runtime exactly is, so it''s probably not running
can you explain to me in short, what it is, and how i set it?

the error occures also with the fullscreen flag, unfortunately.

bony

if you found any spelling errors, you may keep them.
:) if you found any spelling errors, you may keep them. :)
The directx sdk comes with it. It is an option when you install. There is also a shortcut to it under the SDK folder on the startmenu. The subfolder install runtime has the option to change between the two. Alternatively you can change the setting in the control panel on the directx applet. Here you can also adjust the amount of data that is output to the debugger.
ok i''ll try that - thanks!
:) if you found any spelling errors, you may keep them. :)

This topic is closed to new replies.

Advertisement