• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 772
  • Last Modified:

List Running Process - Compile Error

I have compilation problems.

This function will determine whether a process is running.

I am compiling with DEV C++ , and getting the error:

Undefined Reference to GetModuleBaseName,
'' EnumProcessModules

Open in new window

// HEADER and INCLUDE files
#include <windows.h>
#include "resource.h"
#include "functions.cpp"
#include <tchar.h>
#include <stdio.h>
#include <string>

#include <psapi.h>

* Determine whether a Process is running
* This function will enum through open processes
* and determine whether or not a specific process is 
* currently open and running.
* @param    string   Name of the process to see is open
* @return   bool     True if process is open, False otherwise
bool isRunning(string pName)
     unsigned long aProcesses[1024], cbNeeded, cProcesses;
          return false;
     cProcesses = cbNeeded / sizeof(unsigned long);
     for(unsigned int i=0; i<cProcesses; i++)
         HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, aProcesses[i]);
         char buffer[50];
         if(pName == string(buffer))
             return true; 
     return false;


Open in new window

I don't know why this is happening! Any suggestions?
1 Solution
Julian HansenCommented:
Do you have the psapi lib in your project - sounds like it is not finding the GetModuleBaseName function - which is defined in PSAPI.lib
You have to either 1) Point the compiler to use the proper "libpsapi.a", or 2) Add "-lpsapi.a" as a Custom Compiler Command

For (1), use Project -> Project Options -> Parameters -> Add Library or Object via a GUI and point the file dialog to one of:
Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib/libpsapi.a (for MinGW64)
Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib32/libpsapi.a (for MinGW64, 32bit mode)
Dev-Cpp/MinGW32/lib/libpsapi.a (for vanilla MinGW)

For (2), use Tools -> Compiler Options -> Custom Compiler Command (top edit field). Add: -l/<correct-path-to-library>/libpsapi.a
edvinsonAuthor Commented:
Thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now