Solved

List Running Process - Compile Error

Posted on 2013-06-28
3
733 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 56

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

756 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