Author Topic: HidP_GetUsages not working  (Read 6399 times)

MacDie_88

  • Member
  • ***
  • Posts: 7
HidP_GetUsages not working
« on: June 10, 2014, 04:01:48 pm »
 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:

Code: [Select]
[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:
Code: [Select]
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:
Code: [Select]
                                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


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

MacDie_88

  • Member
  • ***
  • Posts: 7
Re: HidP_GetUsages not working
« Reply #2 on: June 13, 2014, 11:03:27 am »
Jan,

I tried to used it in the way shown in the link that you posted but I keep getting the same error.  I have tried many approaches and I have tried to search for this but not success.

Is there any other approach for this?

Thanks

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HidP_GetUsages not working
« Reply #3 on: June 13, 2014, 05:29:12 pm »
See this, you'll need to translate from VB:

http://janaxelson.com/forum/index.php?topic=1269.0