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应该是另一个进程中的句柄吗?那它在这个进程是应该是不可见的呀。

解决方案 »

  1.   

    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应该是另一个进程中的句柄,它应该是只读的
      

  2.   

    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.
      

  3.   

    hSnapShot 是CreateToolhelp32Snapshot创建的,当然死循环了。
    因该是小刚娃的方法