1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
// FOO.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "FOO.h"
using namespace std;
DWORD getPid(string procName)
{
HANDLE hsnap;
PROCESSENTRY32 pt;
hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pt.dwSize = sizeof(PROCESSENTRY32);
wstring wsProcName = wstring(procName.begin(),procName.end()); //pravish conversion zaradi if-a vav do while cikala
do
{
if(!wcscmp(pt.szExeFile, wsProcName.c_str()))
{
DWORD pid = pt.th32ProcessID;
CloseHandle(hsnap);
return pid;
}
}
while(Process32Next(hsnap, &pt));
CloseHandle(hsnap);
return 0;
}
string getPname(DWORD PID)
{
HANDLE hsnap;
PROCESSENTRY32 pt;
hsnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pt.dwSize = sizeof(PROCESSENTRY32);
Process32Next(hsnap, &pt);
//wstring wsProcName = wstring(procName.begin(),procName.end()); //pravish conversion zaradi if-a vav do while cikala
do
{
if(PID == pt.th32ProcessID )
{
wstring strp (pt.szExeFile);
string pname (strp.begin(),strp.end());
//DWORD pid = pt.th32ProcessID;
CloseHandle(hsnap);
return pname;
}
}
while(Process32Next(hsnap, &pt));
CloseHandle(hsnap);
return 0;
}
BOOL ThisIsOurProcess(HANDLE procHandle)
{
DWORD PID;
PID = GetProcessId(procHandle);
string arrCh = getPname(PID);
BOOL h = arrCh.compare("notepad++.exe");
return (PID!=0 && !h );
}
BOOL WINAPI TerminateProcessCallback(HANDLE procHandle, UINT exitCode)
{
MessageBox(0,TEXT("sometext"),TEXT("nothingspecial"),MB_OK);
if((int)procHandle>0 && ThisIsOurProcess(procHandle))
{
return false;
}
else
{
return k(procHandle,exitCode);
}
}
|