private string FindFirstVolume() { // Need at least some length on initial call or we'll get ERROR_INVALID_PARAMETER _buffer.EnsureCharCapacity(400); _findHandle = Imports.FindFirstVolumeMountPointW( _volumeName, _buffer, _buffer.CharCapacity); if (_findHandle.IsInvalid) { WindowsError error = Error.GetLastError(); switch (error) { // Not positive on this case as I haven't been able to get this API // to fully work correctly yet. case WindowsError.ERROR_MORE_DATA: _buffer.EnsureCharCapacity(_buffer.CharCapacity + 64); return(FindFirstVolume()); case WindowsError.ERROR_NO_MORE_FILES: _lastEntryFound = true; return(null); default: throw error.GetException(); } } _buffer.SetLengthToFirstNull(); return(_buffer.ToString()); }
private void CloseHandle() { _findHandle?.Dispose(); _findHandle = null; }