Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectInput GUID compare

Started by Void Jun 18, 2018 at 1:06 PM 10 replies 5.8k views
Original Post
Void
Void

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?

DoctorGlow
DoctorGlow

What does your debugger says?

Void
Void

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


dinput.jpg

Hodgman
Hodgman

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.

Void
Void

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))
      ;


Endurion
Endurion

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 ) )


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Void
Void

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;
}



Endurion
Endurion

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;
}


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Void
Void

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.

SoldierOfLight
SoldierOfLight

A GUID is 128 bits. A DWORD is 32 bits. You can't assign a GUID to a DWORD.

Void
Void

Oh I see my problem , I should be using DIDFT_GETINSTANCE instead of the GUID parameter in the callback, it is a different variable, I should have read the docs more clearly. Thanks for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.