I'm trying to get in the habit of making clean/correct code, so i'm asking you guys to let me know if you see anything.. no matter how small it is.. I could change in this simple code. I'm posting this here because there seems to be quite a few people to actually know what they are talking about.
Code:
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;
int main()
{
HANDLE hProcessSnapShot;
PROCESSENTRY32 pProcessEntry;
cout << "DEBUG: Attempting to create CreateToolhelp32Snapshot()" << endl;
hProcessSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
if (hProcessSnapShot != INVALID_HANDLE_VALUE) {
cout << "DEBUG: hProcessSnapShot = " << hProcessSnapShot << endl;
} else {
cout << "ERROR: CreateToolhelp32Snapshot() - " << GetLastError() << endl;
return 1;
}
cout << "DEBUG: Filling value of pProcessEntry.dwSize" << endl;
pProcessEntry.dwSize = sizeof(PROCESSENTRY32);
cout << "DEBUG: pProcessEntry.dwSize = " << pProcessEntry.dwSize << endl;
if (Process32First(hProcessSnapShot, &pProcessEntry))
{
cout << "DEBUG: Starting process main loop..." << endl;
} else {
cout << "ERROR: Process32First()" << GetLastError() << endl;
return 1;
}
do
{
cout << "[" << pProcessEntry.szExeFile << "]" << endl;
} while (Process32Next(hProcessSnapShot, &pProcessEntry));
CloseHandle(hProcessSnapShot);
return 0;
}