public IEnumerable <ModuleEntry> GetModules() { ModuleEntry.Native native = new ModuleEntry.Native(); native.dwSize = (uint)Marshal.SizeOf <ModuleEntry.Native>(); try { bool success = Module32FirstW(handle, ref native); if (!success) { throw new Win32Exception(); } } catch (Win32Exception err) when(err.NativeErrorCode == ErrNoMoreFiles) { yield break; } catch (Win32Exception err) when(err.NativeErrorCode == IncompleteReadException.ErrorNumber) { throw new IncompleteReadException(err); } yield return(native.AsManaged()); for (; ;) { try { bool success = Module32NextW(handle, ref native); if (!success) { throw new Win32Exception(); } } catch (Win32Exception err) when(err.NativeErrorCode == ErrNoMoreFiles) { yield break; } catch (Win32Exception err) when(err.NativeErrorCode == IncompleteReadException.ErrorNumber) { throw new IncompleteReadException(err); } yield return(native.AsManaged()); } }
internal static extern bool Module32NextW(SafeToolhelp32SnapshotHandle handle, ref ModuleEntry.Native moduleEntry);