Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Module32First (kernel32)
 
.
Summary

C# Signature:

[DllImport("kernel32.dll")]
static extern bool Module32First(IntPtr hSnapshot, ref MODULEENTRY32 lpme);

User-Defined Types:

See struct MODULEENTRY32

Notes:

None.

Tips & Tricks:

http://pastebin.com/BzD1jdmH

Notes:

None.

Sample Code:

Tips & Tricks:

Please add some!

For example:

    ----------------
    int procIDDDDDDDDDDDDD = Process.GetCurrentProcess().Id;
    ----------------
    static void EnumProcessModules(int procIDDDDDDDDDDDDD)
    {//http://pastebin.com/BzD1jdmH
        var snapshot = CreateToolhelp32Snapshot(SnapshotFlags.Module | SnapshotFlags.Module32, (uint)procIDDDDDDDDDDDDD);
        MODULEENTRY32 mod = new MODULEENTRY32() { dwSize = (uint)Marshal.SizeOf(typeof(MODULEENTRY32)) };
        if (!Module32First(snapshot, ref mod))
        return;

Sample Code:

Please add some!

        List<string> modules = new List<string>();
        do
        {
        modules.Add(mod.szModule);
        }
        while (Module32Next(snapshot, ref mod));
        Console.WriteLine("OK");
    }

Alternative Managed API:

System.Diagnostics.Process class contains many module, process, and thread methods.

For example:

    using System.Diagnostics;
    ...
    private void DumpModuleInfo(IntPtr hProcess)
    {
    uint pid = Process.GetProcessById(hProcess).Id;
    uint pid = GetProcessId(hProcess);
    foreach (Process proc in Process.GetProcesses())
    {
        if (proc.Id == pid)
        {
        foreach (ProcessModule pm in proc.Modules)
        {
        Console.WriteLine("{0:X8} {1:X8} {2:X8} {3}", (int)pm.BaseAddress,
        (int)pm.EntryPointAddress, (int)pm.BaseAddress + pm.ModuleMemorySize, pm.ModuleName);
        }
        }
    }
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions