Reading the running process from OS and displaying it through C++!

This code will read the running process from OS and display it (C++). Specifically, the OS here is Windows XP. The Problem(error) is in (i think) prototype. By the way, it displays following errors.

Error 1 : error LNK2019: unresolved external symbol _EnumProcesses@12 referenced in function _main

Error 2 : error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "void __cdecl DisplayProcessNameAndID(unsigned long)" (?DisplayProcessNameAndID@@YAXK@Z)

Error 3 : error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "void __cdecl DisplayProcessNameAndID(unsigned long)" (?DisplayProcessNameAndID@@YAXK@Z)

Error 4 : fatal error LNK1120: 3 unresolved externals C:\Documents and Settings\Windows\My Documents\Visual Studio 2008\Projects\a\Debug\a.exe

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
45
46
#include <afxwin.h>

#include <iostream>
#include <string.h>

#include "psapi.h"
unsigned int i;

using namespace std;
void DisplayProcessNameAndID(DWORD processID);
void main()
{

   DWORD aProcesses[1024], cbNeeded, cProcesses;
   if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
      return;
  
   cProcesses = cbNeeded / sizeof(DWORD);


   for ( i = 0; i < cProcesses; i++ )
   {
   if( aProcesses[i] != 0 )
          DisplayProcessNameAndID( aProcesses[i] );
   }
};
void DisplayProcessNameAndID( DWORD processID )
{
   TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
  HANDLE hProcess = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ) ;`                                                                     

   if (NULL != hProcess )
   {
      HMODULE hMod;
      DWORD cbNeeded;
      if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
      {
         GetModuleBaseName( hProcess, hMod, szProcessName,
            sizeof(szProcessName)/sizeof(TCHAR) );
      }
   };
   CString str;
   str.Format("Text:%s, PID : %u", szProcessName, processID );
   AfxMessageBox(str);
   CloseHandle( hProcess );
   }
Oh ok thhank you. It solved the problem :)
Topic archived. No new replies allowed.