Changeset 1530
- Timestamp:
- 1/15/2010 4:19:35 AM (3 years ago)
- Location:
- branches/eraser6/CodeReview/Eraser.Util
- Files:
-
- 2 edited
-
KernelApi.cs (modified) (1 diff)
-
VolumeInfo.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Util/KernelApi.cs
r1360 r1530 1152 1152 [return: MarshalAs(UnmanagedType.Bool)] 1153 1153 public static extern bool GetVolumePathNamesForVolumeName( 1154 string lpszVolumeName, IntPtr lpszVolumePathNames, uint cchBufferLength,1154 string lpszVolumeName, StringBuilder lpszVolumePathNames, uint cchBufferLength, 1155 1155 out uint lpcchReturnLength); 1156 1156 -
branches/eraser6/CodeReview/Eraser.Util/VolumeInfo.cs
r1528 r1530 44 44 45 45 //Get the paths of the said volume 46 IntPtr pathNamesBuffer = IntPtr.Zero; 47 string pathNames = string.Empty; 48 try 49 { 50 uint currentBufferSize = KernelApi.NativeMethods.MaxPath; 46 string pathNames; 47 { 51 48 uint returnLength = 0; 52 pathNamesBuffer = Marshal.AllocHGlobal((int)(currentBufferSize * sizeof(char))); 49 StringBuilder pathNamesBuffer = new StringBuilder(); 50 pathNamesBuffer.EnsureCapacity(KernelApi.NativeMethods.MaxPath); 53 51 while (!KernelApi.NativeMethods.GetVolumePathNamesForVolumeName(VolumeId, 54 pathNamesBuffer, currentBufferSize, out returnLength)) 55 { 56 if (Marshal.GetLastWin32Error() == 234/*ERROR_MORE_DATA*/) 57 { 58 Marshal.FreeHGlobal(pathNamesBuffer); 59 currentBufferSize *= 2; 60 pathNamesBuffer = Marshal.AllocHGlobal((int)(currentBufferSize * sizeof(char))); 61 } 52 pathNamesBuffer, (uint)pathNamesBuffer.Capacity, out returnLength)) 53 { 54 if (Marshal.GetLastWin32Error() == 234 /*ERROR_MORE_DATA*/) 55 pathNamesBuffer.EnsureCapacity((int)returnLength); 62 56 else 63 57 throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); 64 58 } 65 59 66 pathNames = Marshal.PtrToStringUni(pathNamesBuffer, (int)returnLength); 67 } 68 finally 69 { 70 if (pathNamesBuffer != IntPtr.Zero) 71 Marshal.FreeHGlobal(pathNamesBuffer); 60 if (pathNamesBuffer.Length < returnLength) 61 pathNamesBuffer.Length = (int)returnLength; 62 pathNames = pathNamesBuffer.ToString().Substring(0, (int)returnLength); 72 63 } 73 64
Note: See TracChangeset
for help on using the changeset viewer.
