Click to See Complete Forum and Search --> : error of type cast in calling _beginthreadex


spynet
April 17th, 2003, 04:43 AM
Hi,

I have a problem of casting..
Thi is the source code:

bool CNTService_Sniffer::StartSniffer()
{


//Start del thread
unsigned int m_uiThreadID;

hThread =(HANDLE) _beginthreadex(
0, 0, ProcessAsThread, //ThreadFunction
0, 0, &m_uiThreadID


);

SetThreadPriority(hThread, THREAD_PRIORITY_NORMAL);
WaitForSingleObject( hThread, INFINITE );

return true;
}


the error is:
!!!!
error C2664: '_beginthreadex' : cannot convert parameter 3 from 'unsigned int (void *)' to 'unsigned int (__stdcall *)(void *)'
None of the functions with this name in scope match the target type


PLEASE HELP ME!! I DO NOT UNERSTAND WHAT IS THE CORRECT CAST..
THANK YOU FOR ATTENTION.

BYProcessAsThread

mahanare
April 17th, 2003, 08:06 AM
you may feel the discussion at the following thread is some way related to you.
check it out.
i feel you need to do static casting as explained in the following link.

http://www.codeguru.com/forum/showthread.php?s=&threadid=240008


cheers
mahanare

pfeifer
April 17th, 2003, 08:12 AM
if you want to create a thread using _beginthreadex, you must pass a function using __stdcall calling convention. to solve your problem, you can either change the calling convention of your thread function (prefixing the keyword __stdcall to the declaration of the function), or use _beginthread instead, whitch requires a thread function with the __cdecl calling convention.

Example for the first way:

// thread function declaration:
int __stdcall ProcessAsThread( void * p )
{
...
}


Example for the second way:
_beginthread( ProcessAsThread, 0, 0);

I hope it help you.

pfeifer
April 17th, 2003, 08:13 AM
it is not possible to cast between calling conventions

Andreas Masur
April 17th, 2003, 09:28 AM
For further information take a look at this FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=231241)...