?
Solved

List Running Process - Compile Error

Posted on 2013-06-28
3
Medium Priority
?
742 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 58

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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
Suggested Courses

801 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