Exemplo n.º 1
0
        public static string GetMessage(this Win32Error errorCode)
        {
            StringBuilder buffer = new StringBuilder(0x100);

            if (Win32.FormatMessage(0x3200, IntPtr.Zero, (int)errorCode, 0, buffer, buffer.Capacity, IntPtr.Zero) == 0)
            {
                return("Unknown error (0x" + ((int)errorCode).ToString("x") + ")");
            }

            StringBuilder result = new StringBuilder();
            int           i      = 0;

            while (i < buffer.Length)
            {
                if (!char.IsLetterOrDigit(buffer[i]) &&
                    !char.IsPunctuation(buffer[i]) &&
                    !char.IsSymbol(buffer[i]) &&
                    !char.IsWhiteSpace(buffer[i]))
                {
                    break;
                }

                result.Append(buffer[i]);
                i++;
            }

            return(result.ToString().Replace("\r\n", ""));
        }
Exemplo n.º 2
0
        public static string GetMessage(this Win32Error errorCode)
        {
            String255 buffer = new String255();

            unsafe
            {
                if ((buffer.Length = (byte)Win32.FormatMessage(
                         0x3200,
                         IntPtr.Zero,
                         (int)errorCode,
                         0,
                         new IntPtr(buffer.Buffer),
                         String255.MaximumLength,
                         IntPtr.Zero
                         )) == 0)
                {
                    return("Unknown error (0x" + ((int)errorCode).ToString("x") + ")");
                }

                String255 result = new String255();

                for (int i = 0; i < buffer.Length; i++)
                {
                    char c = buffer.Buffer[i];

                    if (!char.IsLetterOrDigit(c) &&
                        !char.IsPunctuation(c) &&
                        !char.IsSymbol(c) &&
                        !char.IsWhiteSpace(c))
                    {
                        break;
                    }

                    result.Append(c);
                }

                return(result.ToString().Replace("\r\n", ""));
            }
        }