Click to See Complete Forum and Search --> : Threads ahhhh


polus
October 4th, 2005, 04:33 PM
Hi, Im trying to create a worker thread and have followed/read several guides. I get this error when trying to compile:


error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'void (void)'


I dont understand, there is a funtion that takes void, void:
void CFModAudio::PlayThread( void )

Please help.


void CFModAudio::Play()
{
running = TRUE;
AfxBeginThread( PlayThread, (LPVOID)this );
}

UINT CFModAudio::PlayThread( LPVOID pcAudio )
{
CFModAudio *cAudio = (CFModAudio *)pcAudio;
cAudio->PlayThread();
return 0;
}

void CFModAudio::PlayThread( void )
{
// Do the worker task...
}

Siddhartha
October 4th, 2005, 04:35 PM
I dont understand, there is a funtion that takes void, void:
void CFModAudio::PlayThread( void )It actually does not.

Observe your code closely - it returns UINT!

UINT CFModAudio::PlayThread( LPVOID pcAudio ) ;)

Siddhartha
October 4th, 2005, 04:41 PM
[ redirected ]

Regards,
Siddhartha

polus
October 4th, 2005, 04:46 PM
Penny................Drop

Still gives me the error :( hmmm


msdn:
pfnThreadProc
Points to the controlling function for the worker thread. Cannot be NULL. This function must be declared as follows:
UINT MyControllingFunction( LPVOID pParam );

My Function

UINT PlayThread( LPVOID pcAudio );

Error

error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'

Siddhartha
October 4th, 2005, 04:52 PM
Actually you have two PlayThread functions, one of which return UINT and another void (just noticed).

Is the thread function static?
Check this FAQ (http://www.codeguru.com/forum/showthread.php?t=312452) for details.

polus
October 4th, 2005, 04:56 PM
hehe thats where I got it from :)

Just realised, no static! given that static is vital to the operation of the new thread, I shall just go and kick myself in the head!

Thanks :)

Siddhartha
October 4th, 2005, 05:02 PM
You are welcome... ;)

BTW, the function that is static, returns an UINT and accepts a LPVOID is best suited to your task.