本文介绍了OpenThread()返回NULL Win32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得对此有一个明显的答案,但是它一直在困扰着我.我在C ++中有一些遗留代码,当它尝试调用OpenThread()时会中断.我正在Visual C ++ 2008 Express Edition中运行它.程序首先获取调用线程的ThreadID,然后尝试将其打开,如下所示:

I feel like there is an obvious answer to this, but it's been eluding me. I've got some legacy code in C++ here that breaks when it tries to call OpenThread(). I'm running it in Visual C++ 2008 Express Edition. The program first gets the ThreadID of the calling thread, and attempts to open it, like so:

ThreadId threadId = IsThreaded()吗? thread_id::: GetCurrentThreadId();

ThreadId threadId = IsThreaded() ? thread_id : ::GetCurrentThreadId();

HANDLE threadHandle = OpenThread(THREAD_ALL_ACCESS,FALSE,threadId);

HANDLE threadHandle = OpenThread(THREAD_ALL_ACCESS, FALSE, threadId);

现在这是我不明白的地方:如果线程ID是当前线程的ID,它是否已经打开?这可能就是为什么它返回NULL的原因吗?

Now here's what I don't understand: if the thread ID is the current thread's ID, isn't it already open? Could that be why it's returning NULL?

任何反馈将不胜感激.

Any feedback would be appreciated.

推荐答案

也许您要求访问过多(THREAD_ALL_ACCESS),尽管我认为您对自己的线程几乎拥有所有权限.尝试减少对您真正需要的访问.

Maybe you're asking for too much access (THREAD_ALL_ACCESS), though I'd think that you'd have pretty much all permissions to your own thread. Try reducing the access to what you really need.

GetLastError()返回什么?

更新:

看看来自MSDN的评论:

Take a look at this comment from MSDN:

这篇关于OpenThread()返回NULL Win32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 00:15