private FormatMessage ( int dwFlags, IntPtr lpSource, int dwMessageId, int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr va_list_arguments ) : int | ||
dwFlags | int | |
lpSource | IntPtr | |
dwMessageId | int | |
dwLanguageId | int | |
lpBuffer | StringBuilder | |
nSize | int | |
va_list_arguments | IntPtr | |
return | int |
// Gets an error message for a Win32 error code. internal static String GetMessage(int errorCode) { StringBuilder sb = StringBuilderCache.Acquire(512); int result = Win32Native.FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, IntPtr.Zero, errorCode, 0, sb, sb.Capacity, IntPtr.Zero); if (result != 0) { // result is the # of characters copied to the StringBuilder. return(StringBuilderCache.GetStringAndRelease(sb)); } else { StringBuilderCache.Release(sb); return(SR.Format(SR.UnknownError_Num, errorCode)); } }
// 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 { return(Environment.GetResourceString("UnknownError_Num", errorCode)); } }