Windows 10 (32bit)
C++ Qt5.6.0 - minGW49_32
Hello,
I'm trying to get some code working to get a list of running processes.
I'm working from within QtCreator.
MinGW-users - Problem using <psapi.h>
c++ - Adding external library into Qt Creator project - Stack Overflow
The sites I've looked at all seem to say add psapi.lib to the the compiler flags.
add "-lpsapi" to your compiler command
LIBS += -L/path/to -lpsapi
I don't seem to have psapi.lib on my system. A search of my Qt directory shows:-
libpsapi.a
dhvpsapi.h
psapi.h
Any suggestions, Please!
Regards
Code:
void MainWindow::getProcesses()
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
//unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return; //err msg
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( uint i = 0; i < cProcesses; i++ )
if( aProcesses[i] != 0 )
PrintProcessNameAndID( aProcesses[i] );
}
Code:
void MainWindow::PrintProcessNameAndID(DWORD processID)
{
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR) );
}
}
// Print the process name and identifier.
_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
CloseHandle( hProcess );
}
Code:
compile errors:-
error: undefined reference to `EnumProcessModules@16'
error: undefined reference to `GetModuleBaseNameA@16'
error: undefined reference to `EnumProcesses@12'
:-1: error: release/mainwindow.o: bad reloc address 0xc88 in section `.rdata'