Jump to content
  • Advertisement
Sign in to follow this  
Fixxer

Direct Draw 7: Need Help With 2 Errors

This topic is 4674 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

Ok, Right now I am adding 2d support into my game engine. I have 2 errors so far trying to just get a basic DD App running. Here is the source file and errors.
/*********************************************************************************
*
*	Insane Game Engine
*	(c)2005 Nathan Krygier. All Rights Reserved.
*
***********************************************************************************/
#include <ddraw.h>
#include <dsound.h>
#include <dmksctrl.h>
#include <dmusici.h>
#include <dmusicc.h>
#include <dinput.h>
#include "main.h"

void InitDirectDraw7(HWND hwnd)
{
		LPDIRECTDRAW7				lpDirectDraw			= NULL; // Direct Draw Interface 7
		LPDIRECTDRAWSURFACE7		lpPrimaryDDSurface		= NULL; // Direct Draw Surface 7
		DDSURFACEDESC2				ddSD;							// Direct Draw Surface Description

		// Create the Direct Draw Interface
		if(FAILED(DirectDrawCreateEx(NULL,(void **)&lpDirectDraw,IID_IDirectDraw7,NULL)))
		{
			MessageBox(NULL,Error_CreateInterface,Interface_Error, MB_OK);
		}

		// Set The Direct Draw Cooperation Level
		if(FAILED(lpDirectDraw->SetCooperativeLevel(hwnd,DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
												DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
		{
			MessageBox(NULL,Error_SetCooperationLevel,Cooperation_Error, MB_OK);
		}

		// Set The Display Mode
		if(FAILED(lpDirectDraw->SetDisplayMode(Display_Width,Display_Height,Display_Depth,0,0)))
		{
			MessageBox(NULL,Error_SetDisplay,Display_Error, MB_OK);
		}

		// Clear the description and set the size of it
		memset(&ddSD,0,sizeof(ddSD));
		ddSD.dwSize = sizeof(ddSD);

		// Enable the valid fields
		ddSD.dwFlags = DDSD_CAPS;

		// Request The Primary Surface
		ddSD.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

		// Create Primary Surface
		if(FAILED(lpDirectDraw->CreateSurface(&ddSD, &lpPrimaryDDSurface, NULL)))
		{
			MessageBox(NULL,Error_CreateSurface,Surface_Error, MB_OK);
		}

		// Clear ddSD and set size
		memset(ddSD,0,sizeof(ddSD));
		ddSD.dwSize = sizeof(ddSD);

		// Lock Surface
		if(FAILED(lpPrimaryDDSurface->Lock(NULL,&ddSD,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
		{
			MessageBox(NULL,Error_LockSurface,Surface_Error, MB_OK);
		}

		// Create Aliases
		int mempitch		= ddSD.lPitch;
		unsigned char *video_buffer = ddSD.lpSurface;
}

Errors: ------ Build started: Project: Insane Game Engine, Configuration: Debug Win32 ------ Compiling... main.cpp C:\Program Files\Microsoft DirectX 9.0 SDK (October 2005)\Include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800 .\main.cpp(57) : error C2664: 'memset' : cannot convert parameter 1 from 'DDSURFACEDESC2' to 'void *' No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called .\main.cpp(68) : error C2440: 'initializing' : cannot convert from 'LPVOID' to 'unsigned char *' Conversion from 'void*' to pointer to non-'void' requires an explicit cast Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio\Projects\Insane Game Engine\Insane Game Engine\Debug\BuildLog.htm" Insane Game Engine - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Advertisement
The first error is because you are missing the '&' in the line:

memset(ddSD,0,sizeof(ddSD));

It should be:

memset(&ddSD,0,sizeof(ddSD));


The second error is because you need a cast in the line:

unsigned char *video_buffer = ddSD.lpSurface;

It should be:

unsigned char *video_buffer = (unsigned char *)ddSD.lpSurface;

Share this post


Link to post
Share on other sites
Thanks :-)

Now all thats left are link errors.


------ Build started: Project: Insane Game Engine, Configuration: Debug Win32 ------
Compiling...
main.cpp
C:\Program Files\Microsoft DirectX 9.0 SDK (October 2005)\Include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
Linking...
main.obj : error LNK2019: unresolved external symbol _IID_IDirectDraw7 referenced in function "void __cdecl InitDirectDraw7(struct HWND__ *)" (?InitDirectDraw7@@YAXPAUHWND__@@@Z)
C:\Documents and Settings\Owner\My Documents\Visual Studio\Projects\Insane Game Engine\Debug\Insane Game Engine.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio\Projects\Insane Game Engine\Insane Game Engine\Debug\BuildLog.htm"
Insane Game Engine - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
Ok I have my plot pixel function all set, well almost.
Im getting this runtime error:

Unhandled exception at 0x00401005 in Insane Game Engine.exe: 0xC0000005: Access violation reading location 0x00000000.

and

No symbols are loaded for any call stack frame. The source code cannot be displayed.

Here is my plot pixel function, and my call to it


// DRAWS A DIRECT DRAW 7 PIXEL
void DrawPixelDD7(int ix, int iy, int ialpha, int ired, int igreen, int iblue,
unsigned int *video_buffer, int lpitch32)
{
// build color word
unsigned int pixel = _RGB32BIT(ialpha,ired,igreen,iblue);

// write data
video_buffer[ix + iy*lpitch32] = pixel;
}

// LOCKS THE DIRECT DRAW 7 SURFACE
void LockSurfaceDD7()
{
if(FAILED(lpPrimaryDDSurface->Lock(NULL,&ddSD,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
{
MessageBox(NULL,Error_LockSurface,Surface_Error, MB_OK);
}
}

// UNLOCKS THE DIRECT DRAW SURFACE
void UnlockSurfaceDD7()
{
if(FAILED(lpPrimaryDDSurface->Unlock(NULL)))
{
MessageBox(NULL,Error_LockSurface,Surface_Error, MB_OK);
}
}





LockSurfaceDD7();
DrawPixelDD7(40,40,0,255,0,0,video_buffer,lpitch32);
UnlockSurfaceDD7();




[Edited by - Fixxer on December 18, 2005 2:36:48 PM]

Share this post


Link to post
Share on other sites
Your mempitch and video_buffer variables are local variables to your InitDirectDraw7 function. So, setting video_buffer to ddSD.lpSurface doesn't have any effect on your (presumably) global video_buffer variable. Thus, when you go to draw a pixel, video_buffer isn't pointing at your surface.

Share this post


Link to post
Share on other sites
I changed it and still get the same errors.

Ok I have my plot pixel function all set, well almost.
Im getting this runtime error:

Unhandled exception at 0x00401005 in Insane Game Engine.exe: 0xC0000005: Access violation reading location 0x00000000.

and

No symbols are loaded for any call stack frame. The source code cannot be displayed.

Here is my plot pixel function, and my call to it


// DRAWS A DIRECT DRAW 7 PIXEL
void DrawPixelDD7(int ix, int iy, int ialpha, int ired, int igreen, int iblue)
{
// build color word
unsigned int pixel = _RGB32BIT(ialpha,ired,igreen,iblue);

// write data
video_buffer[ix + iy*lpitch32] = pixel;
}

// LOCKS THE DIRECT DRAW 7 SURFACE
void LockSurfaceDD7()
{
if(FAILED(lpPrimaryDDSurface->Lock(NULL,&ddSD,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
{
MessageBox(NULL,Error_LockSurface,Surface_Error, MB_OK);
}
}

// UNLOCKS THE DIRECT DRAW SURFACE
void UnlockSurfaceDD7()
{
if(FAILED(lpPrimaryDDSurface->Unlock(NULL)))
{
MessageBox(NULL,Error_LockSurface,Surface_Error, MB_OK);
}
}





LockSurfaceDD7();
DrawPixelDD7(40,40,0,255,0,0);
UnlockSurfaceDD7();


Share this post


Link to post
Share on other sites
You have a NULL pointer somewhere. I just noticed that ALL of the variables you reference in your Init function are local variables. So NONE of your global variables (lpDirectDraw, lpPrimaryDDSurface, etc) are getting set.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!