Announcement

Collapse
No announcement yet.

USB2GetBenchmarkResults c# call for USB2dll.dll

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • USB2GetBenchmarkResults c# call for USB2dll.dll

    Trying to get C# call using VS2017 to work, I have gotten loopback to work, but USB2GetBenchmarkResults gives me a write access error. Below is code. Any help would be very appreciated.

    Code:
    [DllImport("USB2DLL.dll",EntryPoint = "USB2GetBenchmarkResults", CallingConvention = CallingConvention.Cdecl)]
            [return: MarshalAs(UnmanagedType.I1)]
            static extern bool USB2GetBenchmarkResults([Out] int iOperations, [Out] int iErrors, [Out] float maxRate, [Out] float maxReadrate, [Out] float maxWriteRate, [Out] float avgRate, [Out] float avgPossible);
    Code:
                int loopCount = 0;
                int errorCount = 0;
                float maxRate = 0f;
                float maxReadrate = 0f;
                float maxWriteRate = 0f;
                float avgRate = 0f;
                float avgPossible = 0f;
    
                USB2GetBenchmarkResults(loopCount, errorCount, maxRate, maxReadrate, maxWriteRate, avgRate, avgPossible);


  • #2
    We don't use C# here so can't offer much insight. What's the exact error message you are getting. Is it at compile or run time?

    Looking at the above code should you be using the c# "ref" keyword when calling the function?
    Code:
     
     USB2GetBenchmarkResults(ref loopCount, ref errorCount, ref maxRate, ref maxReadrate, ref  maxWriteRate, ref avgRate, ref avgPossible);

    Comment


    • #3
      Thanks for getting back to me, unfortunately the compiler does not like the ref keyword on the call, but the actually exception is the attached image. I get the exception only when the function is called. The GetLoopbackresults works great.
      Click image for larger version

Name:	dllcallexception.png
Views:	189
Size:	21.9 KB
ID:	43970

      Comment


      • #4
        It looks like one (or all) of the variables being passed in to GetLoopbackresults is NULL (calling USB2GetBenchmarkResults(NULL, ...) would cause this sort of behaviour).

        It may have something to do with the way float values are handled in C# as that is the main difference i can see between USB2GetLoopbackResults and USB2GetBenchmarkResults. Possibly you need to use 'double' in c# rather than float (https://www.codeproject.com/Articles...ng-Simple-Type).

        Comment


        • #5
          That wasn't the issue, but I have a few other things I want to try. When I figure it out I will post back here my results for others that may encounter this also.

          Thanks again.

          Comment


          • #6
            Tim, you were right had to combine all elements together. Thank you very much!

            Code:
                   [DllImport("USB2DLL.dll", EntryPoint = "USB2GetBenchmarkResults", CallingConvention = CallingConvention.Cdecl)]
                    [return: MarshalAs(UnmanagedType.I1)]
                    static extern bool USB2GetBenchmarkResults(ref int iOperations, ref int iErrors, ref double maxRate, ref double maxReadrate, ref double maxWriteRate, ref double avgRate, ref double avgPossible);
            Code:
                       int loopCount = 0;
                        int errorCount = 0;
                        double maxRate =0;
                        double maxReadrate = 0;
                        double maxWriteRate = 0;
                        double avgRate = 0;
                        double avgPossible = 0;
                        double floatTest = 0;
            
                        USB2GetBenchmarkResults(ref loopCount, ref errorCount, ref maxRate, ref maxReadrate, ref maxWriteRate, ref avgRate, ref avgPossible);

            Comment

            Working...
            X