Jump to content
  • Advertisement
Void

DX11 DirectInput GUID compare

Recommended Posts

Hi, I'm trying to do a comparision with DirectInput GUID e.g GUID_XAxis, GUID_YAxis from a value I get from GetProperty

eg
DIPROPRANGE propRange;

DIJoystick->GetProperty (DIPROP_RANGE, &propRange.diph);

// This will crash
if (GUID_XAxis == MAKEDIPROP (propRange.diph.dwObj))
  ;

How should I be comparing the GUID from GetProperty?

Share this post


Link to post
Share on other sites
Advertisement

The == operator is overloaded by VS. For some reason, it cannot show GUID properly

 

dinput.jpg

Share this post


Link to post
Share on other sites

I'm not familiar with this part of DirectInput, but some issues to fix first: You have to fill in propRange before you pass it to GetProperty, or else it will fail, and you have to check whether GetProperty fails or not.

Share this post


Link to post
Share on other sites

I omitted the error checking and other parts for readability, the whole that crashes is this

 


BOOL CALLBACK	EnumAxesCallback (const DIDEVICEOBJECTINSTANCE* instance, VOID* context)
{

  DIPROPRANGE propRange;
  propRange.diph.dwSize       = sizeof (DIPROPRANGE);
  propRange.diph.dwHeaderSize = sizeof (DIPROPHEADER);
  propRange.diph.dwHow        = DIPH_BYID;
  propRange.diph.dwObj        = instance->dwType;
  propRange.lMin              = -1000;
  propRange.lMax              = +1000;

  // ok 
  if (FAILED (DIJoystick->SetProperty (DIPROP_RANGE, &propRange.diph)))
      return DIENUM_STOP;

  // ok
  if (FAILED (DIJoystick->GetProperty (DIPROP_RANGE, &propRange.diph)))
      return DIENUM_STOP;

  // crash if I try to compare GUID
  if (GUID_XAxis == MAKEDIPROP (propRange.diph.dwObj))
      ;

 

Share this post


Link to post
Share on other sites
Posted (edited)

MAKEDIPROP treats the parameter as a pointer to a GUID. dwObj isn't one. 

instance has guidType however, so this should work:

 

if ( GUID_XAxis == MAKEDIPROP( &instance->guidType ) )

 

Edited by Endurion

Share this post


Link to post
Share on other sites

Hmm, not so sure it works. none of the ID match in enum callback, I plugged in a xbox360 controller

 

struct GUIDName
{
	GUID	Guid;
	string	GuidString;
};

GUIDName guidNames [] = 
{
	 { GUID_XAxis,          "GUID_XAxis"          }
	,{ GUID_YAxis,          "GUID_YAxis"          }
	,{ GUID_ZAxis,          "GUID_ZAxis"          }
	,{ GUID_RxAxis,         "GUID_RxAxis"         }
	,{ GUID_RyAxis,         "GUID_RyAxis"         }
	,{ GUID_RzAxis,         "GUID_RzAxis"         }
	,{ GUID_Slider,         "GUID_Slider"         }
	,{ GUID_Button,         "GUID_Button"         }
	,{ GUID_Key,			"GUID_Key"            }
	,{ GUID_POV,			"GUID_POV"            }
	,{ GUID_SysMouse,       "GUID_SysMouse"       }
	,{ GUID_SysKeyboard,    "GUID_SysKeyboard"    }
	,{ GUID_Joystick,       "GUID_Joystick"       }
	,{ GUID_SysMouseEm,     "GUID_SysMouseEm"     }
	,{ GUID_SysMouseEm2,    "GUID_SysMouseEm2"    }
	,{ GUID_SysKeyboardEm,  "GUID_SysKeyboardEm"  }
	,{ GUID_SysKeyboardEm2, "GUID_SysKeyboardEm2" }
};

for (int i = 0; i < sizeof (guidNames)/sizeof (guidNames [0]); ++i)
{
	if (guidNames [i].Guid == MAKEDIPROP (&propRange.diph.dwObj))
		cout << "---------------------------------------" << guidNames [i].GuidString << endl;
}



 

Share this post


Link to post
Share on other sites

You're still using MAKEDIPROP on a non-GUID. A DIPROPRANGE struct simply does not have a GUID as member.

Since you're assumedly inside your EnumObjects callback, the GUID is in your instance object:

 

for (int i = 0; i < sizeof (guidNames)/sizeof (guidNames [0]); ++i)
{
	if (guidNames [i].Guid == instance->guidType )
		cout << "---------------------------------------" << guidNames [i].GuidString << endl;
}

 

Share this post


Link to post
Share on other sites

I'm not in the the EnumObjects callback function, I'm shimming GetProperty function, what takes in &propRange.diph

So I try to access it from the DWORD variable  propRange.diph.dwObj  which is assigned to instance->guidType from caller.

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

  • 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!