internal static string GetMessage(int errorCode) { StringBuilder lpBuffer = new StringBuilder(512); if (Win32Native.FormatMessage(12800, Win32Native.NULL, errorCode, 0, lpBuffer, lpBuffer.Capacity, Win32Native.NULL) != 0) { return(lpBuffer.ToString()); } return(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ResourceManagerCache.GetResourceString("RegistryProviderStrings", "UnknownError_Num"), (object)errorCode.ToString((IFormatProvider)CultureInfo.InvariantCulture))); }
// Gets an error message for a Win32 error code. internal static String GetMessage(int errorCode) { StringBuilder sb = new StringBuilder(512); int result = Win32Native.FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, Win32Native.NULL, errorCode, 0, sb, sb.Capacity, Win32Native.NULL); if (result != 0) { // result is the # of characters copied to the StringBuilder on NT, // but on Win9x, it appears to be the number of MBCS bytes. // Just give up and return the String as-is... String s = sb.ToString(); return(s); } else { string resourceTemplate = RegistryProviderStrings.UnknownError_Num; return(String.Format(CultureInfo.CurrentCulture, resourceTemplate, errorCode.ToString(System.Globalization.CultureInfo.InvariantCulture))); } }