0
#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 从 'unsigned int (__stdcall *)(void)' 转换为 'unsigned int (__stdcall *)(void *)'32

我不小心在网上搜索了一个多小时以找到解决方案,因此非常希望您能提供帮助。

4

1 回答 1

5

您的线程函数应该接收一个void*参数:

unsigned int __stdcall wfshutdown(void *) {
    Sleep(Zeit*60000);
    system("shutdown -s -t 2");
    return 0;
}

当遇到这样的情况时,试着分析编译器的输出。在这种情况下,它表明 _beginthreadex 的第三个参数应该是 an unsigned int (__stdcall *)(void *),但您使用的参数类型为unsigned int (_stdcall *)(void)

Therefore, it's clear that the difference between what's expected and what you have used is the void* argument.

于 2012-03-14T14:35:15.787 回答