DirectInput GUID compare

Started by
10 comments, last by Void 5 years, 10 months ago

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?

Advertisement

What does your debugger says?

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

 

dinput.jpg

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.

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

 

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>

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



 

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>

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.

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

This topic is closed to new replies.

Advertisement