TerminateProcess() with EVC++

B

Bks

I want to terminate a running process from the task manager using evc++
code.

i am using this code :
HANDLE hTl,hProcess;
PROCESSENTRY32 pe;
bool bFound=FALSE;
DWORD dwExplorerProcessID;

hTl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (hTl == INVALID_HANDLE_VALUE)
MessageBox (0,TEXT("INVALID_HANDLE_VALUE"),TEXT(""),0);

pe.dwSize = sizeof(PROCESSENTRY32);

if (!Process32First(hTl, &pe))
MessageBox (0,TEXT("Process32First"),TEXT(""),0);

// if (lstrcmpi(pe.szExeFile, TEXT("explorer.exe")) == 0)
// bFound = TRUE;

while (!bFound && Process32Next(hTl, &pe))
{
if (lstrcmpi(pe.szExeFile, TEXT("explorer.exe")) == 0)
bFound = TRUE;
}

if (bFound)
{
dwExplorerProcessID = pe.th32ProcessID;
hProcess = OpenProcess(0, FALSE, dwExplorerProcessID);
if (hProcess == NULL)
MessageBox (0,TEXT("OpenProcess"),TEXT(""),0);
else
{
if (!TerminateProcess(hProcess, 0))
MessageBox (0,TEXT("TerminateProcess"),TEXT(""),0);
CloseHandle(hProcess);
}

}
CloseToolhelp32Snapshot(hTl);

but it gives me error:


ceSetUp.obj : error LNK2019: unresolved external symbol
CloseToolhelp32Snapshot referenced in function "void __cdecl
StopProcess(void)" (?StopProcess@@YAXXZ)
ceSetUp.obj : error LNK2019: unresolved external symbol Process32Next
referenced in function "void __cdecl StopProcess(void)"
(?StopProcess@@YAXXZ)
ceSetUp.obj : error LNK2019: unresolved external symbol Process32First
referenced in function "void __cdecl StopProcess(void)"
(?StopProcess@@YAXXZ)
ceSetUp.obj : error LNK2019: unresolved external symbol
CreateToolhelp32Snapshot referenced in function "void __cdecl
StopProcess(void)" (?StopProcess@@YAXXZ)


Can any one help me in this ?

Thanks
Bhavin
 
G

Guest

Hi,

It's a linkage error. Your method are not referenced anywhere in the source
code and libraries. Try to link "toolhelp.lib" in your project. (by copying
the file to your project directory and adding it in FileView, Header file
section)

Hope it helps,

Sebastien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top