gpt4 book ai didi

c++ - 等待单个对象 : how to get handle from _beginthreadex

转载 作者:太空狗 更新时间:2023-10-29 20:15:34 25 4
gpt4 key购买 nike

大家好,这是我的代码

#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”

有人可以帮帮我吗?

最佳答案

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

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

(注意:这仅对 _beginthreadex 有效)

关于c++ - 等待单个对象 : how to get handle from _beginthreadex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12605966/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com