Archived

This topic is now archived and is closed to further replies.

Game Programming for Dummies code problem

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

Hi. I have the book "Game Programming For Dummies" and the code on the CD just doesn't work. I have Directx8 and VC++ 6.0 and I think that's the problem. I can't compile a single sourcefile on the CD (almost). I really want to learn game programming and this book is very good except the sourcefiles. I was woundering if anyone of you have this book and the CD and have gotten the code to work with VC++ 6.0 and Directx8. If you have, could you please post the Chapter16 catalogue (StarFerret Deluxe) or just some other code on the that you have gotten to work modified for VC++ 6 and Directx8 so I can start programming sometime. I get errors on DirectInput and some other stuff. I've been trying to get this to work for a long time but I haven't been able to fix it. Please help. /Lennart Edited by - Lennart on August 14, 2001 2:48:54 PM

Share this post


Link to post
Share on other sites
You have to let us know what sort of errors you are having. It maybe a simple compiler setting or something that you are missing. What exactly happens when you try and compile the code? What sort of errors does the compiler respond with?

Share this post


Link to post
Share on other sites
Ok, here are some errors:

error C2065: ''DSBCAPS_CTRLDEFAULT'' : undeclared identifier
D:\test\Gpdumb2.cpp(1136) : error C2065: ''DirectInputCreate'' : undeclared identifier
D:\test\Gpdumb2.cpp(1163) : error C2065: ''DIDEVTYPE_JOYSTICK'' : undeclared identifier


Now I have tried to change DirectInputCreate to DirectInput8Create (Directx8) but then it says that the function does not take 4 parameters. The function looks like this: if (DirectInputCreate(main_instance,DIRECTINPUT_VERSION,&lpdi,NULL)!=DI_OK)

I don''t know about the other error because I''m just trying to compile the code from the book. If you have the book maybe you could tell me how to fix all this.

Thanks.

Share this post


Link to post
Share on other sites
I discovered that I had some .cpp files in the project that should'nt be there and the only error that comes up now is:
error C2065: 'DSBCAPS_CTRLDEFAULT' : undeclared identifier

It looks like DirectInput is the problem.
Maybe if someone who would like to help me could add me on ICQ and I can send the code or something.

My ICQ is: 5497311

Edited by - Lennart on August 14, 2001 4:34:11 PM

Share this post


Link to post
Share on other sites
To clarify, is the book "Windows Game Programming for Dummies" by Andre LaMothe? Then the code was written for DirectX 5 I think. DirectX IS backwards compatible, but I''ve seen cases where you have to use some special defines in order to compile code written for old versions. Something like #define DIRECTINPUT_VERSION 0x00007. I can''t remember exactly, sorry.

Share this post


Link to post
Share on other sites
Yeah it''s Windows Game Programming for Dummies by Andre LaMonthe.
Heh sorry, I forgot the "Windows" part... my fault.
I added your line to my code and something did happen! I got some new errors! :D
Now I get these errors:

error C2146: syntax error : missing '';'' before identifier ''lpdi''
d:\test\gpdumb2.h(117) : fatal error C1004: unexpected end of file found

All I did was adding the #define DIRECTINPUT_VERSION 0x00007

Thanks for helping though.
Any other sugestions?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi

I had the exact same same problem. It is not a problem with the source code from the book. The books DXInput source will work for the older DirectX SDKs. This probklem is caused by an oversite or error on the part of Microsofts DirectX 8 SDK release. I think they fixed it with an SDK update. I dealt with it by just using the DX8 interface instead. Here is some DX8 code for you. It will do a basic DX8Input set of the keyboard and mouse. Also provided is the release code. The DX8 SDK is actually very easy to follow for Input stuff, so do not be afraid to play around and have a go at it.

Have fun

Toad

LPDIRECTINPUT8 DXInput = NULL; // Pointer to direct input interface
LPDIRECTINPUTDEVICE8 KeyBoard = NULL; // Pointer to keyboard device
LPDIRECTINPUTDEVICE8 MouseDevice = NULL; // Pointer to mouse device
DIMOUSESTATE MouseState; // DirectX Mouse structure

struct DIN_MouseStruct Mouse; // My own Mouse structure
unsigned char KeyState[256]; // Array to hold keyboard state

//=================================================================

bool DIN_SetUp (HINSTANCE HInstance, HWND HWnd)
{
// Get our Direct Input interface handle

if (DirectInput8Create (HInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&DXInput, NULL)!=DI_OK)
return false;

// Get our keyboard device handle

if (DXInput->CreateDevice (GUID_SysKeyboard, &KeyBoard, NULL)!=DI_OK)
return false;

// Set keyboard data format

if (KeyBoard->SetDataFormat (&c_dfDIKeyboard)!=DI_OK)
return false;

// Set cooperation level of keyboard

if (KeyBoard->SetCooperativeLevel (HWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE )!=DI_OK)
return false;

// Attach keyboard device to input stream

if (KeyBoard->Acquire ()!=DI_OK)
return false;

// Get our mouse device handle

if (DXInput->CreateDevice (GUID_SysMouse, &MouseDevice, NULL)!=DI_OK)
return false;

// Set mouse data format

if (MouseDevice->SetDataFormat (&c_dfDIMouse)!=DI_OK)
return false;

// Set cooperation level of mouse

if (MouseDevice->SetCooperativeLevel (HWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE )!=DI_OK)
return false;

// Attach mouse device to input stream

if (MouseDevice->Acquire ()!=DI_OK)
return false;

return true;
}

//==================================================================

// Release our Direct Input stuff

//==================================================================

void DIN_Quit (void)
{
if (KeyBoard)
{
KeyBoard->Unacquire ();
KeyBoard->Release ();
}

if (MouseDevice)
{
MouseDevice->Unacquire ();
MouseDevice->Release ();
}

if (DXInput)
{
DXInput->Release ();
}
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi

I had the exact same same problem. It is not a problem with the source code from the book. The books DXInput source will work for the older DirectX SDKs. This probklem is caused by an oversite or error on the part of Microsofts DirectX 8 SDK release. I think they fixed it with an SDK update. I dealt with it by just using the DX8 interface instead. Here is some DX8 code for you. It will do a basic DX8Input set of the keyboard and mouse. Also provided is the release code. The DX8 SDK is actually very easy to follow for Input stuff, so do not be afraid to play around and have a go at it.

Have fun

Toad

LPDIRECTINPUT8 DXInput = NULL; // Pointer to direct input interface
LPDIRECTINPUTDEVICE8 KeyBoard = NULL; // Pointer to keyboard device
LPDIRECTINPUTDEVICE8 MouseDevice = NULL; // Pointer to mouse device
DIMOUSESTATE MouseState; // DirectX Mouse structure

struct DIN_MouseStruct Mouse; // My own Mouse structure
unsigned char KeyState[256]; // Array to hold keyboard state

//=================================================================

bool DIN_SetUp (HINSTANCE HInstance, HWND HWnd)
{
// Get our Direct Input interface handle

if (DirectInput8Create (HInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&DXInput, NULL)!=DI_OK)
return false;

// Get our keyboard device handle

if (DXInput->CreateDevice (GUID_SysKeyboard, &KeyBoard, NULL)!=DI_OK)
return false;

// Set keyboard data format

if (KeyBoard->SetDataFormat (&c_dfDIKeyboard)!=DI_OK)
return false;

// Set cooperation level of keyboard

if (KeyBoard->SetCooperativeLevel (HWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE )!=DI_OK)
return false;

// Attach keyboard device to input stream

if (KeyBoard->Acquire ()!=DI_OK)
return false;

// Get our mouse device handle

if (DXInput->CreateDevice (GUID_SysMouse, &MouseDevice, NULL)!=DI_OK)
return false;

// Set mouse data format

if (MouseDevice->SetDataFormat (&c_dfDIMouse)!=DI_OK)
return false;

// Set cooperation level of mouse

if (MouseDevice->SetCooperativeLevel (HWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE )!=DI_OK)
return false;

// Attach mouse device to input stream

if (MouseDevice->Acquire ()!=DI_OK)
return false;

return true;
}

//==================================================================

// Release our Direct Input stuff

//==================================================================

void DIN_Quit (void)
{
if (KeyBoard)
{
KeyBoard->Unacquire ();
KeyBoard->Release ();
}

if (MouseDevice)
{
MouseDevice->Unacquire ();
MouseDevice->Release ();
}

if (DXInput)
{
DXInput->Release ();
}
}

Share this post


Link to post
Share on other sites
Thanks alot for helping!

I played around with it for a while but I couldn't get to to work, it's wrong with me, not with your code :D. I'm not sure how to replace the existing code with yours though.
Can we talk over ICQ and I can send you the code and you can have a look at it?

Thanks

ICQ UIN: 5497311

Edited by - Lennart on August 14, 2001 7:31:58 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hi again

I never actually use ICQ, my friends pester me every now and then to download one, but I never get round to it.

If you are happy to supply an email address so we can exchange stuff via email, or just post your code here, I will have a look and do what I can to help out.

How does that sound.

Cheers

Toad

Share this post


Link to post
Share on other sites
Hi.

Yeah that would be great...

my email is: penzo@chello.se

just send me a mail and I'll mail you the code and then we can discuss it

I live in sweden so I have to go to bed now but if you send a mail now I'll reply to you when I wake up

Thanks alot!



Edited by - Lennart on August 14, 2001 8:10:35 PM

Share this post


Link to post
Share on other sites