首页
社区
课程
招聘
[求助]如何打开线程?
发表于: 2007-8-13 10:12 6170

[求助]如何打开线程?

2007-8-13 10:12
6170
windows没有提供OpenThread这种API函数
采用的方法是:
HINSTANCE lib = LoadLibrary("kernel32.dll");
ypedef HANDLE (*MYPROC)(DWORD,BOOL,DWORD);//OpenThread
MYPROC ProcAdd;
f(lib != NULL)
{
        ProcAdd = (MYPROC) GetProcAddress(lib, "OpenThread");
}
HANDLE my_thread = NULL;
my_thread = (ProcAdd) (THREAD_ALL_ACCESS &  (~THREAD_TERMINATE),FALSE,dwThreadID);

但是不知道什么原因,每次运行到my_thread = (ProcAdd) (THREAD_ALL_ACCESS &  (~THREAD_TERMINATE),FALSE,dwThreadID);时就会出问题,提示错误见附件

[课程]Android-CTF解题方法汇总!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 2134
活跃值: (14)
能力值: (RANK:170 )
在线值:
发帖
回帖
粉丝
2
OpenThread
The OpenThread function opens an existing thread object.

HANDLE OpenThread(
  DWORD dwDesiredAccess,  // access right
  BOOL bInheritHandle,    // handle inheritance option
  DWORD dwThreadId        // thread identifier
);

If the function succeeds, the return value is an open handle to the specified process.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks
The handle returned by OpenThread can be used in any function that requires a handle to a thread, such as the wait functions, provided you requested the appropriate access rights. The handle is granted access to the thread object only to the extent it was specified in the dwDesiredAccess parameter.

When you are finished with the handle, be sure to close it by using the CloseHandle function.

Requirements
  Windows NT/2000/XP: Included in Windows 2000 and later.
  Windows 95/98/Me: Included in Windows Me.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.

msdn里面的
2007-8-13 10:24
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
问题已经解决
声明错了,汗
ypedef HANDLE (WINAPI *MYPROC)(DWORD,BOOL,DWORD);//OpenThread
2007-8-13 10:25
0
雪    币: 2134
活跃值: (14)
能力值: (RANK:170 )
在线值:
发帖
回帖
粉丝
4
但是我如下代码成功,呵呵
////////////头文件////////////////////////////////////////////////////////////

#include "windows.h"

#include <stdio.h>

////////////宏定义////////////////////////////////////////////////////////////

////////////全局变量//////////////////////////////////////////////////////////

////////////函数定义//////////////////////////////////////////////////////////

int main(int argc, char *argv[])
{
    // 局部变量
    DWORD dwThreadID = GetCurrentThreadId();
    HINSTANCE lib = LoadLibrary("kernel32.dll");
    typedef HANDLE (*MYPROC)(DWORD,BOOL,DWORD);//OpenThread
    MYPROC ProcAdd;

    // 函数动作
    if(lib != NULL)
    {
        HANDLE my_thread = NULL;
        ProcAdd = (MYPROC) GetProcAddress(lib, "OpenThread");
        my_thread = (ProcAdd) (THREAD_ALL_ACCESS &  (~THREAD_TERMINATE),FALSE,dwThreadID);
        if(NULL != my_thread) printf("open thread success\n");
        FreeLibrary(lib);  
    }
         
    // 返回值
    return 0;
}

不过这个代码挺多余的
2007-8-13 10:35
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
代码风格学习
2007-8-13 19:53
0
游客
登录 | 注册 方可回帖
返回
//