示例#1
0
        public static List<string> GetVolumes()
        {
            try
            {
                const uint bufferLength = 1024;
                StringBuilder volume = new StringBuilder((int)bufferLength, (int)bufferLength);
                List<string> result = new List<string>();

                using (FindFirstVolumeSafeHandle volumeHandle = Imports.FindFirstVolume(volume, bufferLength))
                {
                    if (volumeHandle.IsInvalid)
                    {
                        throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error());
                    }

                    do
                    {
                        result.Add(volume.ToString());
                    } while (Imports.FindNextVolume(volumeHandle, volume, bufferLength));

                    return result;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetVolumes()");
                Debug.WriteLine(ex.Message);
                return new List<string>();
            }
        }
示例#2
0
 public static extern bool FindNextVolume(
     FindFirstVolumeSafeHandle hFindVolume,
     StringBuilder lpszVolumeName,
     uint cchBufferLength);
示例#3
0
 public static extern bool FindNextVolume(
     FindFirstVolumeSafeHandle hFindVolume,
     StringBuilder lpszVolumeName,
     uint cchBufferLength);