Ignore:
Timestamp:
6/18/2010 6:44:31 AM (2 years ago)
Author:
lowjoel
Message:

Fixed error in marshalling managed to unmanaged -- the mount points for any volume would only return a maximum of 1 regardless of how many mountpoints there really were due to the array being null-terminated.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.Util/VolumeInfo.cs

    r2177 r2178  
    9898            { 
    9999                uint returnLength = 0; 
    100                 StringBuilder pathNamesBuffer = new StringBuilder(); 
    101                 pathNamesBuffer.EnsureCapacity(NativeMethods.MaxPath); 
     100                char[] pathNamesBuffer = new char[NativeMethods.MaxPath]; 
    102101                while (!NativeMethods.GetVolumePathNamesForVolumeName(VolumeId, 
    103                     pathNamesBuffer, (uint)pathNamesBuffer.Capacity, out returnLength)) 
     102                    pathNamesBuffer, (uint)pathNamesBuffer.Length, out returnLength)) 
    104103                { 
    105104                    int errorCode = Marshal.GetLastWin32Error(); 
     
    110109                            return result; 
    111110                        case Win32ErrorCode.MoreData: 
    112                             pathNamesBuffer.EnsureCapacity((int)returnLength); 
     111                            pathNamesBuffer = new char[pathNamesBuffer.Length * 2]; 
    113112                            break; 
    114113                        default: 
     
    117116                } 
    118117 
    119                 if (pathNamesBuffer.Length < returnLength) 
    120                     pathNamesBuffer.Length = (int)returnLength; 
    121                 pathNames = pathNamesBuffer.ToString().Substring(0, (int)returnLength); 
     118                pathNames = new string(pathNamesBuffer, 0, (int)returnLength); 
    122119            } 
    123120 
Note: See TracChangeset for help on using the changeset viewer.