大家好,这是我的代码
#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'
有人可以帮助我吗?
答案 0 :(得分:7)
您需要将uintptr_t
转换为HANDLE
类型,这在this page的第二个示例中进行了演示,更具体地说:
HANDLE hThread;
hThread = (HANDLE)_beginthreadex(...);
(注意:这仅适用于_beginthreadex
)