程序代码片段是:GetProcessNameByPID(DWORD processID, char *pathname)
{
//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 (hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
GetModuleFileNameEx(hProcess, hMod, pathname, MAX_PATH);
}
}
//Print the process name and identifier.
//printf("%s (Process ID: %u)\n", szProcessName, processID);
CloseHandle(hProcess);
} 文件的开头,
#include "psapi.h"
#pragma comment(lib,"psapi.lib")在32位下可以编译执行。以64位方式编译,提示:error LNK2001: 无法解析的外部符号 _GetModuleFileNameExA在VS2008下编译,用了好几个版本的psapi.lib文件,都是提示同样的错误。有没有人做过64位下根据进程ID获取全路径的,指教一下
{
//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 (hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
GetModuleFileNameEx(hProcess, hMod, pathname, MAX_PATH);
}
}
//Print the process name and identifier.
//printf("%s (Process ID: %u)\n", szProcessName, processID);
CloseHandle(hProcess);
} 文件的开头,
#include "psapi.h"
#pragma comment(lib,"psapi.lib")在32位下可以编译执行。以64位方式编译,提示:error LNK2001: 无法解析的外部符号 _GetModuleFileNameExA在VS2008下编译,用了好几个版本的psapi.lib文件,都是提示同样的错误。有没有人做过64位下根据进程ID获取全路径的,指教一下
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <psapi.h>void PrintModules( DWORD processID )
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i; // Print the process identifier. printf( "\nProcess ID: %u\n", processID ); // Get a list of all the modules in this process. hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
if (NULL == hProcess)
return; if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
{
for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
{
TCHAR szModName[MAX_PATH]; // Get the full path to the module's file. if ( GetModuleFileNameEx(hProcess, hMods[i], szModName,
sizeof(szModName)/sizeof(TCHAR)))
{
// Print the module name and handle value. _tprintf(TEXT("\t%s (0x%08X)\n"),
szModName, hMods[i]);
}
}
} CloseHandle( hProcess );
}void 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 of the modules for each process. for ( i = 0; i < cProcesses; i++ )
PrintModules( aProcesses[i] );
}
你可以用编译器安装光盘重新repair添加安装
perform sdk 2003版安装后,搜索其中的psapi.h和psapi.lib文件,从标示64位的文件夹下把这两个文件复制到项目文件夹里面,编译就通过了。
看来是原先的lib文件是支持32位的,不能链接,如oyljerry所说。