I am trying to use the HidP_GetUsages routine but I can't figure it out how to use it. I know it returns a list of all the HID control button usages that are on a specified page and are set to ON in a HID report. All the approaches that I have tried to use has been giving me error of corrupt memory.
Do you know how to use this routine? If so can you give me some guidance?
Here is how I'm declaring the hid dll:
[DllImport("hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern Boolean HidP_SetUsageValue(Int32 ReportType, Int32 UsagePage, Int32 LinkCollection, Int32 Usage, Int32 UsageValue, IntPtr PreparesedData, Byte[] lpReportBuffer, Int32 ReportBufferLength);
I have an internal function called GetUsages:
internal Boolean GetUsages(Int32 ReportType, Int32 UsagePage, Int32 LinkCollection, ref Int32[] UsageList, Int32 UsageLength, IntPtr PreparsedData, Byte[] lpReportBuffer, Int32 ReportBufferLength)
{
Boolean success;
try
{
success = NativeMethods.HidP_GetUsages(ReportType, UsagePage, LinkCollection, UsageList, UsageLength, PreparsedData, lpReportBuffer, ReportBufferLength);
}
catch (Exception ex)
{
DisplayException(ModuleName, ex);
throw;
}
return success;
}
And I'm calling this in a main function:
UsageList = new Int32[255];
UsageLength = 255;
UsageList[0] = 0;
_myHid.GetUsages(2, UsagePage, LinkCollection, ref UsageList, UsageLength, preparsedData, FeatureReportBuffer, FeatureReportBuffer.Length);
result = 0;
for (j = 0; j < 254;j++)
{
if(UsageList[j]==Usage)
{
result = 1;
}
}
I think my problem might be with the UsageList or UsageLength parameters, because I have used all the other parameters such as : UsagePage,LinkCollection, preparsedData, FeatureReportBuffer, adn FeatureReportBuffer.Lenght. All of them have worked fine on all other declarations.
Thanks