I have created an app in which I want a thread to handle listen-UDP separately and make me a buffer, but when I try to pass it to thread it says there are compatibility issues
hThread = CreateThread(
NULL, // default security attributes
0, // use default stack size
start, // thread function name
&buffer, // argument to thread function
0, // use default creation flags
&dwThreadId);
my start function is
void start(buffer_t *buffer)
{
SOCKET s;
struct sockaddr_in server, si_other;
int slen , recv_len;
char buf[BUFLEN];
WSADATA wsa;
}
and the error is
1 IntelliSense: argument of type "void (*)(buffer_t *buffer)" is incompatible with parameter of type "LPTHREAD_START_ROUTINE" c:\users\madihamalik\documents\visual studio 2010\projects\udp listener\udp listener\listerner.c 189 12 UDP listener
Try below code that might help you..
DWORD start(LPVOID lpdwThreadParam)
{
buffer_t *buffer = (buffer_t *)lpdwThreadParam; //Type cast your argument here
SOCKET s;
struct sockaddr_in server, si_other;
int slen, recv_len;
char buf[BUFLEN];
WSADATA wsa;
...
}
来源:https://stackoverflow.com/questions/30073470/incompatible-types-when-creating-thread-in-windows