C++ Can';t编译C++;使用_beginthreadex编程 #包括 #包括 #包括 //#包括“windowstate.cpp” //DWORD WINAPI MyThreadFunction(LPVOID lpParam); 使用名称空间std; int Zeit; 无符号整数uu stdcall wfshutdown(){ 睡眠(Zeit*60000); 系统(“关闭-s-t 2”); 返回0; } 无效关机(){ coutzeit; 如果(Zeit==0){ 返回; } //窗口状态(0); 处理hThread; 德沃德·特莱德; hThread=(HANDLE)_beginthreadex(NULL,0,&wfshutdown,NULL,0,&threadID); }
我不能运行那个程序。我得到这个错误,我不理解: 错误1错误C2664:“\u beginthreadex”:无法将参数3从“无符号整数(\u stdcall*)(void)”转换为“无符号整数(\u stdcall*)(void*)”32 我在网上搜索了一个多小时才找到解决方案,但没有成功,C++ Can';t编译C++;使用_beginthreadex编程 #包括 #包括 #包括 //#包括“windowstate.cpp” //DWORD WINAPI MyThreadFunction(LPVOID lpParam); 使用名称空间std; int Zeit; 无符号整数uu stdcall wfshutdown(){ 睡眠(Zeit*60000); 系统(“关闭-s-t 2”); 返回0; } 无效关机(){ coutzeit; 如果(Zeit==0){ 返回; } //窗口状态(0); 处理hThread; 德沃德·特莱德; hThread=(HANDLE)_beginthreadex(NULL,0,&wfshutdown,NULL,0,&threadID); },c++,multithreading,beginthread,beginthreadex,C++,Multithreading,Beginthread,Beginthreadex,我不能运行那个程序。我得到这个错误,我不理解: 错误1错误C2664:“\u beginthreadex”:无法将参数3从“无符号整数(\u stdcall*)(void)”转换为“无符号整数(\u stdcall*)(void*)”32 我在网上搜索了一个多小时才找到解决方案,但没有成功, 因此,我非常希望您能提供帮助。您的线程函数应该收到一个void*参数: #include <iostream> #include <Windows.h> #include <p
因此,我非常希望您能提供帮助。您的线程函数应该收到一个
void*
参数:
#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 );
}
当遇到这种情况时,请尝试分析编译器输出。在本例中,它指示_beginthreadex的第三个参数应该是无符号int(u stdcall*)(void*)
,但您使用的参数类型是无符号int(_stdcall*)(void)
因此,很明显,预期值和您使用的值之间的差异是
void*
参数。您的线程函数应该接收一个void*
参数:
#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 );
}
当遇到这种情况时,请尝试分析编译器输出。在本例中,它指示_beginthreadex的第三个参数应该是无符号int(u stdcall*)(void*)
,但您使用的参数类型是无符号int(_stdcall*)(void)
因此,很明显,预期结果与您使用的结果之间的区别在于
void*
参数。+1,特别是关于如何使用编译器输出的参数。正是在这种情况下,您应该暂停,看看编译器到底想告诉您什么。+1特别是如何使用编译器输出。在这种情况下,您应该暂停,看看编译器到底想告诉您什么。