Someone can say if I’m using it right ?
LPTSTR nameProc = "";
...
GetProcessImageFileName( hProcess, nameProc, 50 );
printf("name process : %s\n", nameProc);
I’m not used with the win32 types,
the 2nd argument of the GetProcessImageFileName requires a LPTSTR typedef and the third one takes a DWORD variable.
if not the method maybe i’m not printing the value of nameProc the right way ? (it prints an empty string by the way)
thanks in advance.
(please try to avoid leading me to some win32 api documents, i have no intention to learn about it, i just need to trace the usage memory of one process, therefore I won’t no longer deal with win types)
EDIT (updated code):
void printMemoryInfo( DWORD processID ) {
HANDLE hProcess;
TCHAR nameProc[MAX_PATH];
printf("\nProcess ID: %u\n", processID);
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID );
if (hProcess == NULL) return;
if (GetProcessImageFileName( hProcess, nameProc, sizeof(nameProc)/sizeof(*nameProc) )==0)
printf("error\n");
else printf("%s\n", nameProc);
}
int main (void) {
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded )) {
return 1;
}
cProcesses = cbNeeded/sizeof(DWORD);
for (i=0; i < cProcesses; i++) {
printMemoryInfo( aProcesses[i] );
}
return 0;
}
nameProcneeds to be a mutable buffer as it is an output parameter, at the moment it will probably just crash. Change this:to this:
Also pass
MAX_PATHwhere you are passing 50 at the moment.