public static string GetMessage(IntPtr Display, IntPtr ResourceID, IntPtr Serial, byte ErrorCode, XRequest RequestCode, byte MinorCode) {
StringBuilder sb;
string x_error_text;
string error;
string hwnd_text;
string control_text;
Hwnd hwnd;
Control c;
sb = new StringBuilder(160);
XGetErrorText(Display, ErrorCode, sb, sb.Capacity);
x_error_text = sb.ToString();
hwnd = Hwnd.ObjectFromHandle(ResourceID);
if (hwnd != null) {
hwnd_text = hwnd.ToString();
c = Control.FromHandle(hwnd.Handle);
if (c != null) {
control_text = c.ToString();
} else {
control_text = String.Format("<handle {0:X} non-existant>", hwnd.Handle.ToInt32());
}
} else {
hwnd_text = "<null>";
control_text = "<null>";
}
error = String.Format("\n Error: {0}\n Request: {1:D} ({2})\n Resource ID: 0x{3:X}\n Serial: {4}\n Hwnd: {5}\n Control: {6}", x_error_text, RequestCode, MinorCode, ResourceID.ToInt32(), Serial, hwnd_text, control_text);
return error;
}
}