I'm having a problem with _beginthread in microsoft visual studio c++ 10 express: my code:
void __cdecl DashThread( void * Args ) // function without any class refs
{
while(1){
MessageBox::Show("work");
Sleep(5000);
}
_endthread();
}
private:
System::Void button8_Click_1(System::Object^ sender, System::EventArgs^ e) {
HANDLE HDash = ( HANDLE ) _beginthread(DashThread, 0, NULL );
}
and errors:
error C3641: 'DashThread' : invalid calling convention '__cdecl ' for function compiled with /clr:pure or /clr:safe
error C2664: 'beginthread' : cannot convert parameter 1 from 'void (_cdecl *)(void *)' to 'void (__cdecl *)(void *)'
From the compiler error it seems you are compiling your project with /clr:pure
or /clr:safe
(in which case you are not programming in C++, but C++/CLI by the way) and thus cannot use the __cdecl
calling convention, which is in turn required by _beginthread
.
If you are programming in C++/CLI (and thus .NET) anyway, then why not just use .NET's threading facilities instead of the strange pseudo-standard-Win32-wrapper _beginthread
?
If you want to use C++/CLI, but still be able to use good old _beginthread
, then try to compile it with just /clr
instead of /clr:pure
, which allows non-managed functions that can have __cdecl
calling convention.