#include "sphostMonitor.h" #include #include #include #include "tlhelp32.h " #pragma comment(lib,"psapi.lib") using namespace std; void getCurrentMemoryInfo(unsigned long *memorySize) { HANDLE handle = GetCurrentProcess(); PROCESS_MEMORY_COUNTERS pmc; GetProcessMemoryInfo(handle, &pmc, sizeof(pmc)); *memorySize = pmc.WorkingSetSize; } void cleanMemory() { EmptyWorkingSet(GetCurrentProcess()); } void getHandleNum(unsigned long *handleNum) { GetProcessHandleCount(GetCurrentProcess(), handleNum); } unsigned long GetProcessIdFromName(char * name) { PROCESSENTRY32 pe; DWORD id = 0; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); pe.dwSize = sizeof(PROCESSENTRY32); if (!Process32First(hSnapshot, &pe)) return 0; do { pe.dwSize = sizeof(PROCESSENTRY32); if (Process32Next(hSnapshot, &pe) == FALSE) break; if (stricmp(pe.szExeFile, name) == 0) { id = pe.th32ProcessID; break; } } while (TRUE); CloseHandle(hSnapshot); return id; }