使用CreateToolhelp32Snapshot却陷入死循环,求助

Neptune2003 2004-03-26 03:23:32
HANDLE hSnapShot = ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS , 0);

PROCESSENTRY32 stProcess;
stProcess.dwSize = sizeof(PROCESSENTRY32);

::Process32First( hSnapShot , &stProcess);

HANDLE hTargetProcess;

while(hSnapShot )
{
if ( stProcess.szExeFile == "draw.exe" ||stProcess.szExeFile == "DRAW.EXE")
{
hTargetProcess = ::OpenProcess( PROCESS_VM_READ | PROCESS_VM_WRITE , NULL , stProcess.th32ProcessID);
::DuplicateHandle(::GetCurrentProcess(), memDC.GetSafeHdc() , hTargetProcess , (void**)&hdc , NULL , NULL , DUPLICATE_SAME_ACCESS);
}

::Process32Next(hSnapShot , &stProcess );

}

::CloseHandle(hSnapShot);

顺便弱弱的问一句DuplicateHandle的用法,第四个参数hdc应该是另一个进程中的句柄吗?那它在这个进程是应该是不可见的呀。
...全文
67 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liotion 2004-03-26
  • 打赏
  • 举报
回复
hSnapShot 是CreateToolhelp32Snapshot创建的,当然死循环了。
因该是小刚娃的方法
StarNCraft 2004-03-26
  • 打赏
  • 举报
回复
解决不了!UP一下!
xuanzg 2004-03-26
  • 打赏
  • 举报
回复
2.
[out] Pointer to a variable that receives the value of the duplicate handle. This handle value is valid in the context of the target process.
If lpTargetHandle is NULL, the function duplicates the handle, but does not return the duplicate handle value to the caller. This behavior exists only for backward compatibility with previous versions of this function. You should not use this feature, as you will lose system resources until the target process terminates.

xuanzg 2004-03-26
  • 打赏
  • 举报
回复
1.
while(1)
{
if ( stProcess.szExeFile == "draw.exe" ||stProcess.szExeFile == "DRAW.EXE")
{
hTargetProcess = ::OpenProcess( PROCESS_VM_READ | PROCESS_VM_WRITE , NULL , stProcess.th32ProcessID);
::DuplicateHandle(::GetCurrentProcess(), memDC.GetSafeHdc() , hTargetProcess , (void**)&hdc , NULL , NULL , DUPLICATE_SAME_ACCESS);
}

if(!::Process32Next(hSnapShot , &stProcess );) break;

}

2.第四个参数hdc应该是另一个进程中的句柄,它应该是只读的

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧