我尝试在我的应用程序中使用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;
}
答案 0 :(得分: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;
}