Sign in to follow this  

DirectInput Help Please!

This topic is 3318 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'm sorry for like 2-3 threads but I need this badly(sort of). Ok here's the code:
#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 != DI_OK)
		return 0;

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

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


	return 1;
}

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

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

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

	return 1;
}
This part is where the debug says its wrong:
HRESULT result = dimouse->SetDataFormat(&c_dfDIMouse);
Someone please help me Thanks, Brandon

Share this post


Link to post
Share on other sites
Quote:
Original post by streamer
Try:

dinput->CreateDevice(GUID_SysMouseEm2, &dimouse, NULL);


That didn't work either. But when I debugged it, I found out that dimouse was a NULL pointer. Any more things you think could be wrong with it?

Brandon

Share this post


Link to post
Share on other sites
1. Using DirectInput for keyboard or mouse input is a terrible, terrible idea and will just cause your app to break on a large number of systems

2. DirectX functions can return any one of 2 billion possible codes for success, and 2 billion for failure. You're only checking one success code - use SUCCEEDED, not testing for DI_OK.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
1. Using DirectInput for keyboard or mouse input is a terrible, terrible idea and will just cause your app to break on a large number of systems

2. DirectX functions can return any one of 2 billion possible codes for success, and 2 billion for failure. You're only checking one success code - use SUCCEEDED, not testing for DI_OK.


Ok, what do I use then???

Share this post


Link to post
Share on other sites
Quote:
Original post by BrandonisMaster
Quote:
Original post by Evil Steve
1. Using DirectInput for keyboard or mouse input is a terrible, terrible idea and will just cause your app to break on a large number of systems

2. DirectX functions can return any one of 2 billion possible codes for success, and 2 billion for failure. You're only checking one success code - use SUCCEEDED, not testing for DI_OK.


Ok, what do I use then???


Well, WM_MOUSEMOVE, WM_LBUTTONDOWN / UP, WM_RBUTTONDOWN / UP and WM_CHAR , WM_KEYDOWN messages [smile]

Share this post


Link to post
Share on other sites

mine looks like



LPDIRECTINPUT8 g_pDI; // The DirectInput object
HRESULT hr;

g_pDI = NULL;

if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) )
{
TraceT("Create DirectInput8 Error."));
return false;
}




Try to include this define before dinput include:

#define DIRECTINPUT_VERSION 0x0800
#include<dinput.h>


Handle possible errors, log them, you will much faster find where the bugs are.
For DirectInput8Create these are:
DIERR_BETADIRECTINPUTVERSION
DIERR_INVALIDPARAM
DIERR_OLDDIRECTINPUTVERSION
DIERR_OUTOFMEMORY

what are you getting?

Share this post


Link to post
Share on other sites

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