编译通过,连接错误,各位大虾帮帮忙
#include <windows.h>
#include <stdio.h>
#include "psapi.h "
void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "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) );
}
else return;
}
else return;
// Print the process name and identifier.
printf( "%s (Process ID: %u)\n ", szProcessName, processID );
CloseHandle( hProcess );
}
int main( )
{
// Get the list of process identifiers.
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process.
for ( i = 0; i < cProcesses; i++ )
PrintProcessNameAndID( aProcesses[i] );
return 0;
}
------------------------
正在编译...
Test.cpp
正在链接...
Test.obj : error LNK2019: 无法解析的外部符号 _GetModuleBaseNameA@16 ,该符号在函数 _PrintProcessNameAndID 中被引用
Test.obj : error LNK2019: 无法解析的外部符号 _EnumProcessModules@16 ,该符号在函数 _PrintProcessNameAndID 中被引用
Test.obj : error LNK2019: 无法解析的外部符号 _EnumProcesses@12 ,该符号在函数 _main 中被引用
Debug/Test.exe : fatal error LNK1120: 3 个无法解析的外部命令
[解决办法]
#include "psapi.h "
你还需要链接改 h 文件对应的lib,
将lib 也添加到工程中,
然后编译链接 ~