Sign in to follow this  

Help on my little game

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

I need some help on DirectInput. I just started a few days ago and I'm stuck. So, I uploaded the project file and I want someone to please look at it and find out what's wrong with it. Link: http://www.megaupload.com/?d=3SY1MBQ5 Thanks in advance, Brandon

Share this post


Link to post
Share on other sites
Ok, here's where I narrowed it down to:

#include "dxinput.h"

#define BUTTON_DOWN(obj, button) (obj.rgbButtons[button] & 0x80)

LPDIRECTINPUT8 dinput;
LPDIRECTINPUTDEVICE8 dimouse;
LPDIRECTINPUTDEVICE8 dikeyboard;
LPDIRECTINPUTDEVICE8 dijoystick;
DIMOUSESTATE mouse_state;

char keys[256];

int Init_DirectInput(HWND hWnd)
{
HRESULT result = DirectInput8Create(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void **)&dinput,
NULL);

if(result != SUCCEEDED(result))
return 0;

result = dinput->CreateDevice(GUID_SysMouseEm2, &dimouse, NULL);
if(result != SUCCEEDED(result))
return 0;

result = dinput->CreateDevice(GUID_SysKeyboardEm2, &dikeyboard, NULL);
if(result != SUCCEEDED(result))
return 0;


return 1;
}

int Init_Mouse(HWND hWnd)
{
//help
HRESULT result = dimouse->SetDataFormat(&c_dfDIMouse);
if(result != SUCCEEDED(result))
return 0;

result = dimouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
if(result != SUCCEEDED(result))
return 0;

result = dimouse->Acquire();
if (result != SUCCEEDED(result))
return 0;

return 1;
}


The code that is messed up on debug is this line:

HRESULT result = dimouse->SetDataFormat(&c_dfDIMouse);


I created the device and everything. And I am using a DirectX game programming book to learn.

Thanks,

Brandon

Share this post


Link to post
Share on other sites
Quote:
Original post by BrandonisMaster
Its about the mouse device pointer is NULL.

Quote:
Original post by BrandonisMaster
I created the device and everything.


Then the mouse device pointer shouldn't be NULL.

Quote:
Original post by BrandonisMaster
And I am using a DirectX game programming book to learn.


Then refer to your book on how to use DirectInput.
Or, you could follow any of the DirectInput tutorials, and find the answers you're looking for.

Share this post


Link to post
Share on other sites
Quote:
Original post by BrandonisMaster
All that I want is someone to look at that code and see what is wrong with the device.


It's uninitialized/NULL, that's what's wrong with the mouse device pointer. Which would mean that the device hasn't been created.

Share this post


Link to post
Share on other sites
What's the exact error? Why is it crashing? Is dimouse NULL? Is it not NULL? Did all of your Init_DirectInput calls succeed?

Put the values in a watch window, step through the code, and look at what it does every step of the way and confirm that it's doing what you think it's doing.

Share this post


Link to post
Share on other sites
Quote:
Original post by Grafalgar
What's the exact error? Why is it crashing? Is dimouse NULL? Is it not NULL? Did all of your Init_DirectInput calls succeed?

Put the values in a watch window, step through the code, and look at what it does every step of the way and confirm that it's doing what you think it's doing.


Thanks, I figured out exactly what is wrong with it. It is this right here:

HRESULT result = DirectInput8Create(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&dinput,
NULL);


Now, I don't know what I did wrong, but I know it is wrong. I went through with result as a watch var and it had no stack until this, then it's value went to -858993460. I think that's bad. So, is there some sort of error right there? Because my book says the exact same thing as that.

Regards,

Brandon

Share this post


Link to post
Share on other sites

This topic is 3321 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this