Solved

List Running Process - Compile Error

Posted on 2013-06-28
3
714 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 51

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

19 Experts available now in Live!

Get 1:1 Help Now