EnumProcesses and SKD's

Hi,

I'm trying to use the function EnumProcesses to check whether a process is running or not. But when I try to compile it, it returns an error, (which I don't get). I've looked up some stuff on google, and some pages adviced to install some kind a SDK. I'm using the MingW compiler now, (on Windows XP with Code::Blocks) but I have no idea which SDK, and were (probably MSDN?) I should download it. Does anybody knows something about which SDK I should use (if I really need to use one to compile this code).

These are my errors:
1
2
C:\Source\list_processes.o:list_processes.cpp:(.text+0x16c): undefined reference to `_EnumProcesses@12'
C:\Source\list_processes.o:list_processes.cpp:(.text+0x222): undefined reference to `_GetModuleBaseNameA@16'


On the following peace of code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include <iostream>
#include <string>
#include <windows.h>
#include "psapi.h"

using namespace std;
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;
}


int main()
{
    if(isRunning("MSPAINT.EXE"))
    {
        cout << "Mspaint is running!" << endl;
    }
    else
    {
        cout << "MSPaint is not running!" << endl;
    }

return 0;
}
Last edited on
closed account (z05DSL3A)
You have to tell the linker to use Psapi.lib for those undefined functions. Check to see if it is already available.

Windows SDK can be downloaded here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&displaylang=en
but check if you need it, it is also a DVD ISO image.

Thanks, I've found the MSDN thread with the same info, but the last time I tried to edit something in the compiler/linker, it killed my IDE's for 2 days. Is there some reference on the internet, or can someone give me one, how to tell the linker to use a certain lib?

Best regards, Luke
Last edited on
Topic archived. No new replies allowed.