2

我正在尝试将一些代码移植到 64 位,但似乎其中的线程地址标识符_beginthreadexunsigned int32 位,我无法从函数传递/接收 64 位地址标识符:

uintptr_t _beginthreadex( // NATIVE CODE
   void *security,
   unsigned stack_size,
   unsigned ( __stdcall *start_address )( void * ),
   void *arglist,
   unsigned initflag,
   unsigned *thrdaddr // <-- 32-bit address
);

我查看了MSDN 文档,但没有看到该功能的 64 位版本。我是否包括了错误的标头、每个处理器的标志,或者是否有其他方法可以创建具有 64 位地址标识符的线程?

更新

文档说明该thrdaddr参数是 32 位的:

阈值

Points to a 32-bit variable that receives the thread identifier. Might be NULL, in which case it is not used.
4

3 回答 3

5

thrdaddr参数接收线程ID。它不是线程函数的地址。它似乎是一个命名非常糟糕的参数。

start_address参数是线程函数指针,您可以在该参数中传递您的 64 位函数指针。


您对问题的更新表明您认为线程 ID 是 64 位 Windows 上的 64 位值。这是一个错误的想法。线程 ID 在所有类型的 Windows 上都是 32 位值。

于 2012-02-08T17:26:20.220 回答
1

文档中:

阈值

指向接收线程标识符的 32 位变量。可能为 NULL,在这种情况下不使用它。

换句话说,thrdaddr获取线程 ID。它不是线程的地址。

在 64 位中,所有指针都是 64 位的。所以这只是工作。

于 2012-02-08T17:25:30.683 回答
1

你把一些论点弄混了。您的线程 proc 的地址将作为start_address. thrdaddr是一个可选参数,而不是接收线程 ID。

HANDLE hThread;
unsigned threadID;

hThread = (HANDLE)_beginthreadex(
    NULL,
    0,
    &YourThreadProc, // this is your thread procedure
    NULL,
    0,
    &threadID); // threadID will hold the ID of the new thread
于 2012-02-08T17:27:35.137 回答