-2

我尝试在我的应用程序中使用 CreateThread() 函数,但我得到了奇怪的错误,确切地说:

error: invalid conversion from 'DWORD (__ attribute__((__ stdcall__)) *)() {aka long unsigned int (__ attribute__((__ stdcall__)) *)()}' to 'LPTHREAD_START_ROUTINE {aka long unsigned int (__ attribute__((__ stdcall__)) *)(void*)}' [-fpermissive]

In file included from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/windows.h:50:0,

             from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winsock2.h:22,
             from c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/ws2tcpip.h:19,
             from include/WinSockClass.hpp:3,
             from C:\Users\Jakub\Desktop\offline\Server\main.cpp:15:
c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/winbase.h:1423:26: error:   initializing argument 3 of 'void* CreateThread(LPSECURITY_ATTRIBUTES, DWORD, LPTHREAD_START_ROUTINE, PVOID, DWORD, PDWORD)' [-fpermissive]

第二个指示线

WINBASEAPI HANDLE WINAPI CreateThread(LPSECURITY_ATTRIBUTES,DWORD,LPTHREAD_START_ROUTINE,PVOID,DWORD,PDWORD);

在 winbase.h 中,我不明白发生了什么,在示例中是相同的,但没有错误。我做错了什么?

代码:

#include <iostream>
#include <windows.h>

using namespace std;

int a()
{
   cout << "work";
   return 0;
}
int main(int argc, char **argv)
{
    CreateThread(NULL,0,a,NULL,0,NULL);
    return 0;
}
4

1 回答 1

0

好的,是我的错,这行得通

#include <iostream>
#include <windows.h>

using namespace std;

DWORD WINAPI a(LPVOID lpParameter)
{
   cout << "work";
   return 0;
}
int main(int argc, char **argv)
{
    CreateThread(NULL,0,a,NULL,0,NULL);
    return 0;
}
于 2016-02-27T21:23:15.343 回答