Problem With CreateThread With A Function In Class [WINAPI]

Hello,

I have a problem with CreateThread function from WINAPI in Visual Studio 2015 Update 1, i have a class and on this class i have the function which i need to be called on another thread but i get this error:

Error: invalid type conversion

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class fSServer
{
public:
	fSServer() :iResult(0), wsaData({ 0 }), ServerSock(INVALID_SOCKET), result(NULL), hints({ 0 }) { }
	int Initialize(a_port Port, int SockFamily, int SockType, int Protocol);
	int Create();
	void WINAPI ServerTickProcess();
	inline SOCKET GetServerSock() { return ServerSock; }
	inline int GetLastErr() { return lastErr; }
private:
	WSADATA wsaData;
	int iResult;
	SOCKET ServerSock;
	struct addrinfo *result, hints;
	int lastErr;
	HANDLE tickThread;
	bool threadCreated;
};

int fSServer::Create()
{
	ServerSock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
	if (ServerSock == INVALID_SOCKET)
	{
		lastErr = WSAGetLastError();
		return ErrorType::INVALID_SOCK;
	}

	iResult = bind(ServerSock, result->ai_addr, (int)result->ai_addrlen);
	if (iResult == SOCKET_ERROR) 
	{
		lastErr = WSAGetLastError();
		return ErrorType::SOCKET_ERR;
	}
	freeaddrinfo(result); // We no longer need result

	if(threadCreated != true) tickThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)ServerTickProcess, NULL, 0, 0); // -> error here at third argument, position: ( before "LPTHREAD_START_ROUTINE"

	threadCreated = true;
}


Thank you for reading my topic.
Last edited on
Make ServerTickProcess() static. You can't pass non-static member functions to CreateThread(), only global or static member functions will work.
Also, note that the function pointed to by an LPTHREAD_START_ROUTINE must take as its only parameter an LPVOID. You can use this parameter to pass the this pointer to the callback. To do this, pass this as the fourth parameter to CreateThread().
Thank you for your answer.

Yes, my problem solved thanks to you.
Topic archived. No new replies allowed.