Sign in to follow this  
programmermattc

Problems with DirectX Joysticks

Recommended Posts

I've been working on getting some joystick code running within my program, even getting it running without telling specific buttons what to do would be fine but what happens when I run the program is it begins to launch and then just freezes and stops responding. I've looked around a lot trying to find out more about the Joystick code but haven't found much. Here's what I have in regards to the joystick code.
	
lpdi->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, (void *)this, DIEDFL_ATTACHEDONLY);
	lpdiJoystick->SetDataFormat(&c_dfDIJoystick);
	lpdiJoystick->SetCooperativeLevel(hWnd, DISCL_BACKGROUND |  DISCL_NONEXCLUSIVE);

	DIPROPRANGE dipr;
	dipr.diph.dwSize = sizeof(DIPROPRANGE);
	dipr.diph.dwHeaderSize = sizeof(DIPROPRANGE);
	dipr.diph.dwHow = DIPH_BYID;
	dipr.lMin = -1024;
	dipr.lMax = 1024;

	dipr.diph.dwObj = DIJOFS_X;

	HRESULT hr;

	lpdiJoystick->SetProperty(DIPROP_RANGE, &dipr.diph);
	
	hr = lpdiJoystick->Poll();
	if(FAILED(hr))
	{
		lpdiJoystick->Acquire();
		while(hr == DIERR_INPUTLOST)
			hr = lpdiJoystick->Acquire();
EnumJoysticksCallback is a callback function I have which does the following:
Input_Core *self = (Input_Core *)pContext;
HRESULT hr;

hr = self->lpdi->CreateDevice(pdidInstance->guidInstance, &(self->lpdiJoystick), NULL);

if(FAILED(hr))
	return DIENUM_CONTINUE;

return DIENUM_STOP;
Of course I use self in this sense because EnumJoysticksCallback is a static member of my input class. Finally I have a GetDeviceState() call and my final Unaquire() and Release(). If I comment out everything but the lpdi->EnumDevices() it runs fine but anything else locks-up the program. Anyone have any ideas as to code I can change or code I am missing?

Share this post


Link to post
Share on other sites

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