Solved

List Running Process - Compile Error

Posted on 2013-06-28
3
721 Views
Last Modified: 2013-07-02
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;
     
     if(!EnumProcesses(aProcesses,sizeof(aProcesses),&cbNeeded))
          return false;
          
     cProcesses = cbNeeded / sizeof(unsigned long);
     
     for(unsigned int i=0; i<cProcesses; i++)
     {
         if(aProcesses[i]==0)
         {
             continue;
         }            
         
         HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, aProcesses[i]);
         
         char buffer[50];
         
         GetModuleBaseName(hProcess,0,buffer,50);
         CloseHandle(hProcess);
         
         if(pName == string(buffer))
             return true; 
     }
     
     return false;

}

Open in new window



I don't know why this is happening! Any suggestions?
0
Comment
Question by:edvinson
3 Comments
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 39286325
Do you have the psapi lib in your project - sounds like it is not finding the GetModuleBaseName function - which is defined in PSAPI.lib
0
 
LVL 3

Accepted Solution

by:
komar earned 500 total points
ID: 39286677
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
0
 
LVL 1

Author Closing Comment

by:edvinson
ID: 39295455
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now