Weird error when compiling my client

Hello everyone,

I am new to C++ and learning more about it, grabbed a client for a game from the internet and started to learn stuff.
Now I am running in to some last errors which seems to be fake errors, at least I think they are.

These are the errors I get :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Severity	Code	Description	Project	File	Line	Suppression State
Error	C1903	unable to recover from previous error(s); stopping compilation	tibiaclient	C:\Client\Source\threads\thread.cpp	4	
Error	C2761	'{ctor}' : member function redeclaration not allowed	tibiaclient	C:\Client\Source\threads\thread.cpp	4	
Error	C3646	'm_callback' : unknown override specifier	tibiaclient	C:\Client\Source\threads\thread.cpp	4	
Error	C2091	function returns function	tibiaclient	C:\Client\Source\threads\thread.cpp	3	
Error	C2059	syntax error : '*'	tibiaclient	C:\Client\Source\threads\thread.cpp	3	
Error	C2238	unexpected token(s) preceding ';'	tibiaclient	c:\client\source\threads\thread.h	14	
Error	C2059	syntax error : '('	tibiaclient	c:\client\source\threads\thread.h	14	
Error	C2143	syntax error : missing ')' before ';'	tibiaclient	c:\client\source\threads\thread.h	9	
Error	C2059	syntax error : ')'	tibiaclient	c:\client\source\threads\thread.h	9	
Error	C2059	syntax error : '__stdcall'	tibiaclient	c:\client\source\threads\thread.h	9	
Error	C2238	unexpected token(s) preceding ';'	tibiaclient	c:\client\source\threads\thread.h	14	
Error	C2059	syntax error : '('	tibiaclient	c:\client\source\threads\thread.h	14	
Error	C2143	syntax error : missing ')' before ';'	tibiaclient	c:\client\source\threads\thread.h	9	
Error	C2059	syntax error : ')'	tibiaclient	c:\client\source\threads\thread.h	9	
Error	C2059	syntax error : '__stdcall'	tibiaclient	c:\client\source\threads\thread.h	9	


So here is the thread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "thread.h"

Thread::Thread(DWORD WINAPI (*f)(void* p), LPVOID argv, bool execute /*= true*/){
	m_callback = f;
	m_argument = argv;
	m_executed = false;

	if(execute){
		m_executed = CreateThread(NULL, 0, m_callback, m_argument, 0, NULL) != NULL;
	}
}

bool Thread::start(){
	if(!m_executed){
		m_executed = CreateThread(NULL, 0, m_callback, m_argument, 0, NULL) != NULL;
	}
}

bool Thread::isRunning(){
	return m_executed;
}


And here is the thread.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef __THREADH__
#define __THREADH__

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

class Thread {
	public:
		Thread(WINAPI DWORD (*f)(void* p), LPVOID argv, bool execute = true);

		bool start();
		bool isRunning();
	private:
		DWORD WINAPI (*m_callback)(void* arg);
		LPVOID m_argument;

		bool m_executed;
};

#endif 


I really hope someone can help with this so I can continue my journey !
Kindly regards,

Ralumbi <-- C++ noob
Last edited on
Now I am running in to some last errors which seems to be fake errors, at least I think they are.

I'm not sure I understand what you mean but if the compiler spits out a long list of errors it's often a good idea to fix the first one first and then recompile to see if the other errors are still there because often one error can lead to the compiler thinking there are other errors later in the code.

Error C1903 unable to recover from previous error(s); ...

I'm not used the compiler you are using so I'm not sure but to me it sounds like there are other errors before the ones you have posted. Are you sure there are not more errors if you scroll up?
Last edited on
These are sadly the only errors I've got.. Thats why it makes it weird and I can not understand what is going on here.

I have fixed like ~600 errors before and end up with this one and cannot understand what is wrong in the code.

Kindly regards,

Ralumbi
I'm no expert in Windows-specific coding, or in using calling convention specifiers, but this SO page suggests that you need to modify the syntax for using WINAPI with function pointers wrong:

https://stackoverflow.com/questions/4830355/function-pointer-and-calling-convention

EDIT: It also recommends defining a typedef for your function pointer type. I second that wholeheartedly.
Last edited on
I also am no expert in Windows coding. But your header, line 9 has WINAPI DWORD, while your source code, line 3 has DWORD WINAPI.

Not knowing what the WINAPI macro expands to, I don't know if this is the cause of your problem.

I also wholeheartedly agree to typdeffing the function pointer type.
WINAPI expands to __stdcall - hence the relevance of the SO link I posted.
Hey guys !
Both of you thanks for responding and trying to help me solve the issue..
Sadly I found out how it gets working !

I need to jump into MinGW compiling since the code is not supported for normal windows compiling.

So these errors we've got here are fake errors, as well I want to give with you guys is that the windows compiler uses '__asm' and mingw uses just 'asm' telling it to you so it could help you on any other adventure as well !!!

Again thanks for your time and have a look at my code and I might see you guys next time !

Kindly regards,

Ralumbi
Topic archived. No new replies allowed.