hi admin.. i followed your tip in "HOW TO LIST PROCESS ID IN WINDOWS" thread..and iam trying to compile this code in cygwin ,
$gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe
psapi.h and psapi.lib are in this same folder as process.c file, i am getting lonf list of errors from psapi.lib
Process.c (from http://voice.mytechnopark.com/viewtopic.php?id=51)
[code=c]
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <psapi.h>
void main( )
{
DWORD ProcessesIDs[50], cbNeeded, cProcesses;
unsigned int i;
//The default of <unknown> is given so that if GetModuleBaseNa me does not return
//the base name of the module then <unknown> will be printed instead of the base name.
TCHAR szProcessName[50] = TEXT("<unknown> ");
//if Enumprocess returns zero (fails) then quit the program.
if ( !EnumProcesses( ProcessesIDs, sizeof(Processe sIDs), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// This for loop will be enumerating each process.
for ( i = 0; i < cProcesses; i++ )
{
// Get a handle to the process. The process to which the handle will be returned //will depend on the variable i.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_I NFORMATION | PROCESS_VM_READ , FALSE, ProcessesIDs[i] );
// Get the process name.
if (NULL != hProcess )
{
GetModuleBaseNa me( hProcess, NULL, szProcessName, sizeof(szProces sName)/sizeof(TCHAR) );
}
// Print the process name and identifier.
_tprintf(TEXT(" Processname = %s, PID = %u \n\n"), szProcessName, ProcessesIDs[i]);
//Every handel is to be closed after its use is over.
CloseHandle( hProcess );
//End of for loop.
}
}
[/code]
Output:
psapi.lib:90:73 : warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90:77 : warning: null character(s) ignored
psapi.lib:90:83 : warning: null character(s) ignored
psapi.lib:90: error: stray '\2' in program
psapi.lib:90:91 : warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90: error: stray '\1' in program
psapi.lib:90: error: stray '\6' in program
psapi.lib:90:97 : warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:10 1: warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:11 1: warning: null character(s) ignored
psapi.lib:90:11 4: warning: null character(s) ignored
psapi.lib:91:1: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
psapi.lib:91:9: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
process.c:39: error: conflicting types for 'CloseHandle'
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../include/w32api/winbase.h:1169: error: previous declaration of 'CloseHandl
e' was here
process.c:39: warning: data definition has no type or storage class
process.c:41: error: parse error before '}' token
process.c:42:2: warning: no newline at end of file
P.S : I need this to work ..as it is a very important part of my final year project, please help in compiling this program
thanx in advance ..
$gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe
psapi.h and psapi.lib are in this same folder as process.c file, i am getting lonf list of errors from psapi.lib
Process.c (from http://voice.mytechnopark.com/viewtopic.php?id=51)
[code=c]
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <psapi.h>
void main( )
{
DWORD ProcessesIDs[50], cbNeeded, cProcesses;
unsigned int i;
//The default of <unknown> is given so that if GetModuleBaseNa me does not return
//the base name of the module then <unknown> will be printed instead of the base name.
TCHAR szProcessName[50] = TEXT("<unknown> ");
//if Enumprocess returns zero (fails) then quit the program.
if ( !EnumProcesses( ProcessesIDs, sizeof(Processe sIDs), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// This for loop will be enumerating each process.
for ( i = 0; i < cProcesses; i++ )
{
// Get a handle to the process. The process to which the handle will be returned //will depend on the variable i.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_I NFORMATION | PROCESS_VM_READ , FALSE, ProcessesIDs[i] );
// Get the process name.
if (NULL != hProcess )
{
GetModuleBaseNa me( hProcess, NULL, szProcessName, sizeof(szProces sName)/sizeof(TCHAR) );
}
// Print the process name and identifier.
_tprintf(TEXT(" Processname = %s, PID = %u \n\n"), szProcessName, ProcessesIDs[i]);
//Every handel is to be closed after its use is over.
CloseHandle( hProcess );
//End of for loop.
}
}
[/code]
Output:
psapi.lib:90:73 : warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90:77 : warning: null character(s) ignored
psapi.lib:90:83 : warning: null character(s) ignored
psapi.lib:90: error: stray '\2' in program
psapi.lib:90:91 : warning: null character(s) ignored
psapi.lib:90: error: stray '\3' in program
psapi.lib:90: error: stray '\1' in program
psapi.lib:90: error: stray '\6' in program
psapi.lib:90:97 : warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:10 1: warning: null character(s) ignored
psapi.lib:90: error: stray '\1' in program
psapi.lib:90:11 1: warning: null character(s) ignored
psapi.lib:90:11 4: warning: null character(s) ignored
psapi.lib:91:1: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
psapi.lib:91:9: warning: null character(s) ignored
psapi.lib:91: error: stray '\2' in program
process.c:39: error: conflicting types for 'CloseHandle'
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../include/w32api/winbase.h:1169: error: previous declaration of 'CloseHandl
e' was here
process.c:39: warning: data definition has no type or storage class
process.c:41: error: parse error before '}' token
process.c:42:2: warning: no newline at end of file
P.S : I need this to work ..as it is a very important part of my final year project, please help in compiling this program
thanx in advance ..
Comment