Solved

List Running Process - Compile Error

Posted on 2013-06-28
3
739 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 57

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

726 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