3

大家好,这是我的代码

#include "StdAfx.h"
#include <iostream>
#include <windows.h>
#include <process.h>  


unsigned int __stdcall threadproc(void* lparam)
{
    std::cout << "my thread" << std::endl;
    return 0;
}


int main()
{
    unsigned  uiThread1ID = 0;

    uintptr_t th = _beginthreadex(NULL, 0, threadproc, NULL, 0, &uiThread1ID);
     WaitForSingleObject(th, INFINITE/*optional timeout, in ms*/);
    return 0;
}

但我收到以下错误消息

错误 C2664:“WaitForSingleObject”:无法将参数 1 从“uintptr_t”转换为“HANDLE”

有人可以帮我吗?

4

1 回答 1

7

您需要将uintptr_t类型转换为类型,这在本页HANDLE的第二个示例中进行了演示,更具体地说:

HANDLE hThread;
hThread = (HANDLE)_beginthreadex(...);

(注意:这仅适用于_beginthreadex

于 2012-09-26T16:15:08.367 回答