2014-07-20 58 views
-2

你好,我试图暂停一个线程,但由于某种原因,它不断崩溃的游戏。 这里是我得到你如何暂停一个线程?

void Test(){ 
    SuspendThread((PVOID)0x83593C24);//0x83593C24 The offset from the game 
    Scr_AddInt(1); 
    ResumeThread((PVOID)0x83593C24); 
} 

基本上我试图暂停不是打电话添加诠释比恢复它

+2

线程**不是**某些内存地址。寻找线程ID和进程ID。 – Deduplicator

+0

我发出的threadid是0x8354F7A8,但我没有看到processid http://gyazo.com/13a976b7993ce574ff9489d82110f1cc – HorseFrog

+0

这看起来太大了一个线程ID ... – Deduplicator

回答

0

您需要使用您在创建线程返回线程句柄。请参阅文档CreateThread; SuspendThread;和ResumeThread

特别是,从文档CreateThread

如果函数成功,返回值是一个句柄到新的线程。如果函数失败,返回值为NULL。

实施例:

HANDLE thread_handle = CreateThread(/*args*/); // hold on to this value (and check for failure) 
if (thread_handle == NULL) 
{ 
    // handle creation error 
} 

DWORD suspend_retval = SuspendThread(thread_handle); 
if (suspend_retval == static_cast<DWORD>(-1)) 
{ 
    // handle suspend error 
} 

Scr_AddInt(1); // original work 

DWORD resume_retval = ResumeThread(thread_handle); 
if (resume_retval == static_cast<DWORD>(-1)) 
{ 
    // handle resume error 
} 

这可能是值得的创建封装线程创建,暂停,恢复,和终止的包装类。该类可以在内部执行所有错误检查,并在适当时引发异常。