无法使用_beginthreadex编译C++程序
Can't compile a C++ program with _beginthreadex
#include <iostream>
#include <Windows.h>
#include <process.h>
//#include "windowstate.cpp"
//DWORD WINAPI MyThreadFunction( LPVOID lpParam );
using namespace std;
int Zeit;
unsigned int __stdcall wfshutdown() {
Sleep(Zeit*60000);
system("shutdown -s -t 2");
return 0;
}
void shutdown() {
cout << "When I should shut down your PC(in minutes)" << endl;
cin >> Zeit;
if(Zeit==0) {
return;
}
// windowstate(0);
HANDLE hThread;
DWORD threadID;
hThread = (HANDLE)_beginthreadex( NULL, 0, &wfshutdown, NULL, 0, &threadID );
}
我无法运行该程序。我收到此错误,我不明白:
错误1 错误 C2664:"_beginthreadex":无法将参数 3 从"无符号整数 (__stdcall *((无效("转换为"无符号整数 (__stdcall *((无效 *('32
我毫不掩饰地在网上搜索了一个多小时,以找到解决方案,因此,我非常希望您能提供帮助。
你的线程函数应该收到一个void*
参数:
unsigned int __stdcall wfshutdown(void *) {
Sleep(Zeit*60000);
system("shutdown -s -t 2");
return 0;
}
遇到此类情况时,请尝试分析编译器输出。在这种情况下,它表示要_beginthreadex的第三个参数应该是 unsigned int (__stdcall *)(void *)
,但您使用的是类型 unsigned int (_stdcall *)(void)
的参数。
因此,很明显,预期内容和您使用的内容之间的差异是void*
论点。