Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compilation error

Status
Not open for further replies.

BeerFizz

Technical User
Jan 23, 2004
28
0
0
Hi,

I am trying to incorporate several classes I got off of Code-project (which I think were originally written for Visual C++6.0) into a dialog application under Microsoft Visual C++ .NET 2003.

I am having an issue with a particular call and after spending several hour at this, I am still unable to get it to compile correctly and get the following error:
Code:
error C2664: 'myThread::myThread(LPTHREAD_START_ROUTINE,LPVOID,DWORD,DWORD,BOOL)' : cannot convert parameter 1 from 'DWORD (LPVOID)' to 'LPTHREAD_START_ROUTINE'

this is the line which is calling causing the issue (i contains a reference to a function)
Code:
myThread* serverThread = new myThread(serverHandleThread,(void*)serverArgument);

This is the function prototype:
Code:
DWORD WINAPI serverHandleThread(LPVOID threadInfo);
This is the prototype of the 'class' myThread
Code:
	myThread(
		LPTHREAD_START_ROUTINE pThreadFunc,    // address of thread callback
		LPVOID pThreadFuncParameter=NULL,      // address of callback's parameter,
		DWORD  exeFlags=0,                     // creation flag
		DWORD  sSize=0,                        // stack size
		BOOL   inheritable=FALSE               // inheritable
	);


What is wrong and how do I fix this (explicitly)

Thanks for all help
Phil
 
Thread starting routine should have no return value. It seems the serverHandleThread can't be a thread start routine (it returns DWORD). No legal conversion between DWORD(*)(LPVOID) and VOID(*)(LPVOID) function pointers.

 
I'm using VC++ 2005 express and this code compiles fine for me:
Code:
#include <windows.h>

DWORD WINAPI serverHandleThread( LPVOID threadInfo )
{
    return 0;
}

class myThread
{
private:
	LPTHREAD_START_ROUTINE	m_pThreadFunc;
	LPVOID					m_pThreadFuncParameter;
	DWORD					m_exeFlags;
	DWORD					m_sSize;
	BOOL					m_inheritable;

public:
	myThread(
				LPTHREAD_START_ROUTINE pThreadFunc,    // address of thread callback
				LPVOID pThreadFuncParameter=NULL,      // address of callback's parameter,
				DWORD  exeFlags=0,                     // creation flag
				DWORD  sSize=0,                        // stack size
				BOOL   inheritable=FALSE               // inheritable
			)
	:	m_pThreadFunc( pThreadFunc ),
		m_pThreadFuncParameter( pThreadFuncParameter ),
		m_exeFlags( exeFlags ),
		m_sSize( sSize ),
		m_inheritable( inheritable )
	{}
};

int main( int argc, char* argv[] )
{
	LPVOID serverArgument = NULL;
	myThread* serverThread = new myThread( serverHandleThread, (void*)serverArgument );

	return 0;
}
See if that simplified program still gives you compile errors.
You can try casting serverHandleThread to LPTHREAD_START_ROUTINE, but that shouldn't be necessary.
 
ArkM said:
Thread starting routine should have no return value.
On my system, LPTHREAD_START_ROUTINE looks like this:
Code:
typedef [b]DWORD[/b] (WINAPI *PTHREAD_START_ROUTINE)(
    LPVOID lpThreadParameter
    );
typedef PTHREAD_START_ROUTINE LPTHREAD_START_ROUTINE;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top