I am trying to tell if a hardware device (specifically multitouch digitizer) is disabled.
I can successfully enable/disable the device using the DisableHardware class from here.
I have found the DEVICE_CAPABILITIES struct with property HardwareDisabled. But if I call SetupDiGetDeviceRegistryPropertyW, to return SPDRP_CAPABILITIES, I am unable to convert the returned value (DWORD) to useful uint.
I believe my conversion is wrong from byte[] => uint, I always get 128.
private static bool IsDeviceHardwareDisabeld(IntPtr info, SP_DEVINFO_DATA devdata)
{
Trace.WriteLine("IsDeviceHardwareDisabeld");
uint SPDRP_CAPABILITIES = 0x0000000F;
uint CM_DEVCAP_HARDWAREDISABLED = 16384u;
uint propId = SPDRP_CAPABILITIES;
uint proptype, outsize;
IntPtr buffer = IntPtr.Zero;
try
{
uint buflen = 512;
buffer = Marshal.AllocHGlobal((int)buflen);
outsize = 0;
SetupDiGetDeviceRegistryPropertyW(
info,
ref devdata,
propId,
out proptype,
buffer,
buflen,
ref outsize);
Trace.WriteLine("OUTSIZE: " + outsize.ToString()); // 4
byte[] lbuffer = new byte[outsize];
Marshal.Copy(buffer, lbuffer, 0, (int)outsize);
int errcode = Marshal.GetLastWin32Error();
if (errcode == ERROR_INVALID_DATA) throw new Exception("ERROR_INVALID_DATA");
CheckError("SetupDiGetDeviceRegistryPropertyW", errcode);
uint capabilities = BitConverter.ToUInt32(lbuffer, 0); // always 128
uint bitwise = capabilities & CM_DEVCAP_HARDWAREDISABLED; // always 0
bool isHardwareDisabled = bitwise > 0;
Trace.WriteLine("HARDWAREDISABLED: " + isHardwareDisabled.ToString());
return isHardwareDisabled;
}
finally
{
if (buffer != IntPtr.Zero)
Marshal.FreeHGlobal(buffer);
}
}
My conversion always returns 128 for value of DEVICE_CAPABILITIES.