-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugging.cs
More file actions
47 lines (37 loc) · 1.52 KB
/
Debugging.cs
File metadata and controls
47 lines (37 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
namespace GenericHid
{
/// <summary>
/// Used only in Debug.Write statements.
/// </summary>
///
internal sealed partial class Debugging
{
/// <summary>
/// Get text that describes the result of an API call.
/// </summary>
///
/// <param name="functionName"> the name of the API function. </param>
///
/// <returns>
/// The text.
/// </returns>
internal String ResultOfApiCall( String functionName )
{
var resultString = new String(Convert.ToChar( 0 ), 129 );
// Returns the result code for the last API call.
Int32 resultCode = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
// Get the result message that corresponds to the code.
Int64 temp = 0;
Int32 bytes = NativeMethods.FormatMessage(NativeMethods.FormatMessageFromSystem, ref temp, resultCode, 0, resultString, 128, 0);
// Subtract two characters from the message to strip the CR and LF.
if ( bytes > 2 )
{
resultString = resultString.Remove( bytes - 2, 2 );
}
// Create the String to return.
resultString = Environment.NewLine + functionName + Environment.NewLine + "Result = " + resultString + Environment.NewLine;
return resultString;
}
}
}