You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by ni...@apache.org on 2004/05/28 23:30:02 UTC

cvs commit: logging-log4net/src/Util NativeError.cs SystemInfo.cs

nicko       2004/05/28 14:30:02

  Modified:    src/Util NativeError.cs SystemInfo.cs
  Log:
  Added NativeError.GetLastError method to get the native error for the last windows error.
  
  Revision  Changes    Path
  1.5       +18 -0     logging-log4net/src/Util/NativeError.cs
  
  Index: NativeError.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/NativeError.cs,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NativeError.cs	21 May 2004 22:15:33 -0000	1.4
  +++ NativeError.cs	28 May 2004 21:30:02 -0000	1.5
  @@ -78,6 +78,24 @@
   		#region Public Static Methods
   
   		/// <summary>
  +		/// Create a new instance of the <see cref="NativeError" /> class for the last Windows error.
  +		/// </summary>
  +		/// <returns>
  +		/// An instance of the <see cref="NativeError" /> class for the last windows error.
  +		/// </returns>
  +		/// <remarks>
  +		/// <para>
  +		/// The message for the <see cref="Marshal.GetLastWin32Error"/> error number is lookup up using the 
  +		/// native Win32 <c>FormatMessage</c> function.
  +		/// </para>
  +		/// </remarks>
  +		public static NativeError GetLastError() 
  +		{
  +			int number = Marshal.GetLastWin32Error();
  +			return new NativeError(number, NativeError.GetErrorMessage(number));
  +		}
  +
  +		/// <summary>
   		/// Create a new instance of the <see cref="NativeError" /> class.
   		/// </summary>
   		/// <param name="number">the error number for the native error</param>
  
  
  
  1.4       +2 -4      logging-log4net/src/Util/SystemInfo.cs
  
  Index: SystemInfo.cs
  ===================================================================
  RCS file: /home/cvs/logging-log4net/src/Util/SystemInfo.cs,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SystemInfo.cs	26 Feb 2004 21:44:53 -0000	1.3
  +++ SystemInfo.cs	28 May 2004 21:30:02 -0000	1.4
  @@ -541,14 +541,12 @@
   					moduleName = new StringBuilder(255);
   					if (GetModuleFileName(moduleHandle, moduleName,	moduleName.Capacity) == 0) 
   					{
  -						NativeError nativeError = NativeError.GetError(Marshal.GetLastWin32Error());
  -						throw new NotSupportedException(nativeError.ToString());
  +						throw new NotSupportedException(NativeError.GetLastError().ToString());
   					}
   				} 
   				else 
   				{
  -					NativeError nativeError = NativeError.GetError(Marshal.GetLastWin32Error());
  -					throw new NotSupportedException(nativeError.ToString());
  +					throw new NotSupportedException(NativeError.GetLastError().ToString());
   				}
   
   				return moduleName.ToString();