F
Ich habe mir mal den Code von dem ersten von mir verlinkten Beispiel angeschaut, und dort wird es so gemacht:
TCHAR szFileName[MAX_PATH];
GetProcessName(
dwProcessId),
szFileName,
MAX_PATH
);
Diese Funktion gibt es aber noch nicht fertig, sondern hat der Autor selbst geschrieben:
//
// Return the name of the process by its ID using PSAPI
//
BOOL CCallbackHandler::GetProcessName(
DWORD dwProcessId,
LPTSTR lpFileName,
DWORD dwLen
)
{
BOOL bResult = FALSE;
if (!::IsBadStringPtr(lpFileName, dwLen))
{
::ZeroMemory(
reinterpret_cast<PBYTE>(lpFileName),
dwLen * sizeof(TCHAR)
);
if ((NULL != m_pfnEnumProcessModules) &&
(NULL != m_pfnGetModuleFileNameEx))
{
// Let's open the process
HANDLE hProcess = ::OpenProcess(
PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
FALSE,
dwProcessId
);
if (NULL != hProcess)
{
HMODULE hModuleArray[1024];
DWORD cbNeeded;
DWORD nModules;
// EnumProcessModules function retrieves a handle for
// each module in the specified process.
if (m_pfnEnumProcessModules(
hProcess,
hModuleArray,
sizeof(hModuleArray),
&cbNeeded))
{
// Calculate number of modules in the process
nModules = cbNeeded / sizeof(hModuleArray[0]);
if (nModules > 0)
{
// First module is the EXE.
HMODULE hModule = hModuleArray[0];
DWORD dwCharRead = m_pfnGetModuleFileNameEx(
hProcess,
hModule,
lpFileName,
dwLen
);
} // if
} // if
::CloseHandle(hProcess);
} // if
} // if
} // if
return bResult;
}
Der Code ist eben Bestandteil seiner Klassenhirarchie - du wirst also wohl noch ein paar Änderungen vornehmen müssen