Changeset 1062
- Timestamp:
- 5/16/2009 10:07:16 AM (4 years ago)
- Location:
- branches/eraser6/Eraser.Util
- Files:
-
- 4 edited
-
AdvApi.cs (modified) (2 diffs)
-
KernelApi.cs (modified) (4 diffs)
-
StreamInfo.cs (modified) (3 diffs)
-
VolumeInfo.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/Eraser.Util/AdvApi.cs
r1005 r1062 63 63 NativeMethods.TOKEN_QUERY, out hToken); 64 64 if (!result || hToken == IntPtr.Zero) 65 throw new Win32Exception(Marshal.GetLastWin32Error(), 66 "Could not open process token."); 65 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 67 66 68 67 IntPtr pElevationType = Marshal.AllocHGlobal(Marshal.SizeOf( … … 79 78 //Check the return code 80 79 if (!result) 81 throw new Win32Exception(Marshal.GetLastWin32Error(), 82 "Could not retrieve token information."); 80 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 83 81 84 82 NativeMethods.TOKEN_ELEVATION_TYPE elevationType = -
branches/eraser6/Eraser.Util/KernelApi.cs
r1049 r1062 105 105 } 106 106 107 /// <summary> 108 /// Converts a Win32 Error code to a HRESULT. 109 /// </summary> 110 /// <param name="errorCode">The error code to convert.</param> 111 /// <returns>A HRESULT value representing the error code.</returns> 112 internal static int GetHRForWin32Error(int errorCode) 113 { 114 const uint FACILITY_WIN32 = 7; 115 return errorCode <= 0 ? errorCode : 116 (int)((((uint)errorCode) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000); 117 } 118 119 /// <summary> 120 /// Gets a Exception for the given Win32 error code. 121 /// </summary> 122 /// <param name="errorCode">The error code.</param> 123 /// <returns>An exception object representing the error code.</returns> 124 internal static Exception GetExceptionForWin32Error(int errorCode) 125 { 126 int HR = GetHRForWin32Error(errorCode); 127 return Marshal.GetExceptionForHR(HR); 128 } 129 107 130 public static void GetFileTime(SafeFileHandle file, out DateTime creationTime, 108 131 out DateTime accessedTime, out DateTime modifiedTime) … … 118 141 out modifiedTimeNative)) 119 142 { 120 throw new Win32Exception(Marshal.GetLastWin32Error());143 throw GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 121 144 } 122 145 … … 139 162 out accessedTimeNative, out modifiedTimeNative)) 140 163 { 141 throw new Win32Exception(Marshal.GetLastWin32Error());164 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 142 165 } 143 166 … … 152 175 ref accessedTimeNative, ref modifiedTimeNative)) 153 176 { 154 throw new Win32Exception(Marshal.GetLastWin32Error());177 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 155 178 } 156 179 } -
branches/eraser6/Eraser.Util/StreamInfo.cs
r1049 r1062 137 137 return false; 138 138 139 throw new Win32Exception(Marshal.GetLastWin32Error());139 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 140 140 } 141 141 } … … 246 246 else 247 247 if (!KernelApi.NativeMethods.DeleteFile(FullName)) 248 throw new Win32Exception(Marshal.GetLastWin32Error());248 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 249 249 } 250 250 … … 350 350 (uint)share, IntPtr.Zero, (uint)mode, (uint)options, IntPtr.Zero); 351 351 if (result.IsInvalid) 352 throw new Win32Exception(Marshal.GetLastWin32Error());352 throw KernelApi.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 353 353 return result; 354 354 } -
branches/eraser6/Eraser.Util/VolumeInfo.cs
r1009 r1062 191 191 while (mountpointDir != null); 192 192 193 throw new Win32Exception(4390 /*ERROR_NOT_A_REPARSE_POINT*/); 193 throw Marshal.GetExceptionForHR(KernelApi.GetHRForWin32Error( 194 4390 /*ERROR_NOT_A_REPARSE_POINT*/)); 194 195 } 195 196
Note: See TracChangeset
for help on using the changeset viewer.
