Debugging.cs
author sl
Wed, 14 May 2014 07:53:47 +0200
changeset 1 29c8c6738077
permissions -rw-r--r--
Disabling signing to fix our build.
     1 using System;
     2  
     3 namespace GenericHid
     4 {
     5 	/// <summary>
     6 	/// Used only in Debug.Write statements.
     7 	/// </summary>
     8 	/// 
     9 	internal sealed partial class Debugging
    10     {         
    11         ///  <summary>
    12         ///  Get text that describes the result of an API call.
    13         ///  </summary>
    14         ///  
    15         ///  <param name="functionName"> the name of the API function. </param>
    16         ///  
    17         ///  <returns>
    18         ///  The text.
    19         ///  </returns>
    20           
    21         internal String ResultOfApiCall( String functionName ) 
    22         {
    23 	        var resultString = new String(Convert.ToChar( 0 ), 129 ); 
    24             
    25             // Returns the result code for the last API call.
    26             
    27             Int32 resultCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); 
    28             
    29             // Get the result message that corresponds to the code.
    30 
    31             Int64 temp = 0;
    32 			Int32 bytes = NativeMethods.FormatMessage(NativeMethods.FormatMessageFromSystem, ref temp, resultCode, 0, resultString, 128, 0); 
    33             
    34             // Subtract two characters from the message to strip the CR and LF.
    35             
    36             if ( bytes > 2 ) 
    37             { 
    38                 resultString = resultString.Remove( bytes - 2, 2 ); 
    39             }             
    40             // Create the String to return.
    41 
    42             resultString = Environment.NewLine + functionName + Environment.NewLine + "Result = " + resultString + Environment.NewLine; 
    43             
    44             return resultString;             
    45         }         
    46     }  
    47 }