主题:[讨论]打开计算器后点击按钮就出错
下面是源码:达人有空之余帮我改下,万分感谢
DWORD __stdcall Call_HP()
{
AfxMessageBox("dd");
return 0;
}
void CCT1DlgDlg::OnFdwindow()
{
HWND hwnd = ::FindWindow(0,"计算器");
if (hwnd == NULL)
{
AfxMessageBox("Can not find window");
return;
}
DWORD tid;
HANDLE pid;
GetWindowThreadProcessId(hwnd, &tid);
pid = OpenProcess(PROCESS_ALL_ACCESS, FALSE, tid);
if (pid == 0)
{
AfxMessageBox("Can not open the process!");
return;
}
HANDLE tmpHandle;
DWORD temp2;
void *taddr, *p;
taddr = VirtualAllocEx(pid, NULL, 4096, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pid, taddr, &Call_HP, 4096, 0);
tmpHandle = ::CreateRemoteThread
(pid, NULL, 0, (LPTHREAD_START_ROUTINE)taddr, 0, 0, &temp2);
::WaitForSingleObject(tmpHandle, INFINITE); //等待线程结束
::CloseHandle(tmpHandle); //关闭线程
}
DWORD __stdcall Call_HP()
{
AfxMessageBox("dd");
return 0;
}
void CCT1DlgDlg::OnFdwindow()
{
HWND hwnd = ::FindWindow(0,"计算器");
if (hwnd == NULL)
{
AfxMessageBox("Can not find window");
return;
}
DWORD tid;
HANDLE pid;
GetWindowThreadProcessId(hwnd, &tid);
pid = OpenProcess(PROCESS_ALL_ACCESS, FALSE, tid);
if (pid == 0)
{
AfxMessageBox("Can not open the process!");
return;
}
HANDLE tmpHandle;
DWORD temp2;
void *taddr, *p;
taddr = VirtualAllocEx(pid, NULL, 4096, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(pid, taddr, &Call_HP, 4096, 0);
tmpHandle = ::CreateRemoteThread
(pid, NULL, 0, (LPTHREAD_START_ROUTINE)taddr, 0, 0, &temp2);
::WaitForSingleObject(tmpHandle, INFINITE); //等待线程结束
::CloseHandle(tmpHandle); //关闭线程
}