2017年3月31日 星期五

[C++] Enumerating All Processes, unresolved external symbol _GetModuleBaseNameW

#pragma comment(lib, "Psapi.lib")
#include "psapi.h"

void CdlgSSDMP::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 );

// Release the handle to the process.

CloseHandle( hProcess );
}


REF:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682623(v=vs.85).aspx
https://social.msdn.microsoft.com/Forums/en-US/623ba3e3-7c47-4cf0-80e8-9262f3b47e52/enumprocesses-issue?forum=Vsexpressvc
________________________________________ 3S CONFIDENTIALITY NOTICE: This message and all attachments may contain legally privileged and confidential information. Any unauthorized review, use or distribution by anyone other than the intended recipient is strictly prohibited. If you are not the intended recipient, please contact the sender immediately by replying to the message and delete all copies. Thank you.

沒有留言:

張貼留言