sl@0: using System; sl@0: sl@0: namespace GenericHid sl@0: { sl@0: /// sl@0: /// Used only in Debug.Write statements. sl@0: /// sl@0: /// sl@0: internal sealed partial class Debugging sl@0: { sl@0: /// sl@0: /// Get text that describes the result of an API call. sl@0: /// sl@0: /// sl@0: /// the name of the API function. sl@0: /// sl@0: /// sl@0: /// The text. sl@0: /// sl@0: sl@0: internal String ResultOfApiCall( String functionName ) sl@0: { sl@0: var resultString = new String(Convert.ToChar( 0 ), 129 ); sl@0: sl@0: // Returns the result code for the last API call. sl@0: sl@0: Int32 resultCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error(); sl@0: sl@0: // Get the result message that corresponds to the code. sl@0: sl@0: Int64 temp = 0; sl@0: Int32 bytes = NativeMethods.FormatMessage(NativeMethods.FormatMessageFromSystem, ref temp, resultCode, 0, resultString, 128, 0); sl@0: sl@0: // Subtract two characters from the message to strip the CR and LF. sl@0: sl@0: if ( bytes > 2 ) sl@0: { sl@0: resultString = resultString.Remove( bytes - 2, 2 ); sl@0: } sl@0: // Create the String to return. sl@0: sl@0: resultString = Environment.NewLine + functionName + Environment.NewLine + "Result = " + resultString + Environment.NewLine; sl@0: sl@0: return resultString; sl@0: } sl@0: } sl@0: }