Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
 internal static extern bool Module32NextW(SafeToolhelp32SnapshotHandle handle, ref ModuleEntry.Native moduleEntry);