Ejemplo n.º 1
0
        /// <summary>
        /// Gets the modules that have been loaded by the associated process.
        /// </summary>
        /// <param name="p">The Process.</param>
        /// <returns>An array of type <see cref="ProcessModule"/> that represents the modules that have been loaded by the associated process.</returns>
        public static System.Collections.ObjectModel.ReadOnlyCollection <ProcessModule> GetModules(this Process p)
        {
            List <ProcessModule> modules = new List <ProcessModule>();

            IntPtr handle = NativeMethods.CreateToolhelp32Snapshot(NativeMethods.TH32CS.SNAPMODULE, p.Id);

            if (handle != IntPtr.Zero)
            {
                NativeMethods.MODULEENTRY32 me = new NativeMethods.MODULEENTRY32();
                me.dwSize = Marshal.SizeOf(me);
                bool success = NativeMethods.Module32First(handle, ref me);
                while (success)
                {
                    modules.Add(new ProcessModule(me));

                    success = NativeMethods.Module32Next(handle, ref me);
                }
                NativeMethods.CloseToolhelp32Snapshot(handle);
            }

            return(new System.Collections.ObjectModel.ReadOnlyCollection <ProcessModule>(modules));
        }
Ejemplo n.º 2
0
 internal ProcessModule(NativeMethods.MODULEENTRY32 me)
 {
     this.me = me;
 }