Platform SDK: Performance Monitoring

EnumProcessModules

The EnumProcessModules function retrieves a handle for each module in the specified process.

BOOL EnumProcessModules(
  HANDLE hProcess,      // handle to process
  HMODULE *lphModule,   // array of module handles
  DWORD cb,             // size of array
  LPDWORD lpcbNeeded    // number of bytes required
);

Parameters

hProcess
[in] Handle to the process.
lphModule
[out] Pointer to the array that receives the list of module handles.
cb
[in] Specifies the size, in bytes, of the lphModule array.
lpcbNeeded
[out] Receives the number of bytes required to store all module handles in the lphModule array.

Return Value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

It is a good idea to give EnumProcessModules a large array of HMODULE values, because it is hard to predict how many modules there will be in the process at the time you call EnumProcessModules. To determine if the lphModule array is too small to hold all module handles for the process, compare the value returned in lpcbNeeded with the value specified in cb. If lpcbNeeded is greater than cb, increase the size of the array and call EnumProcessModules again.

To determine how many modules were enumerated by the call to EnumProcessModules, divide the resulting value in the lpcbNeeded parameter by sizeof(HMODULE).

Requirements

  Windows NT/2000: Requires Windows NT 4.0 or later.
  Header: Declared in Psapi.h.
  Library: Use Psapi.lib.

See Also

Process Status Helper Overview, PSAPI Functions, EnumProcesses