_beginthread newbie question
-
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h_beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... }
Any help/pointer will be very helpful. Thankx in advance. -Tareq -
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h_beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... }
Any help/pointer will be very helpful. Thankx in advance. -Tareq -
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h_beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... }
Any help/pointer will be very helpful. Thankx in advance. -TareqIn the Thread function You must specify the Calling convention of the Function Like unsigned __stdcall YourThreadFunction(void* pVoid) { return something; } and try to write the fucntion a a pubic, not a member
-
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h_beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... }
Any help/pointer will be very helpful. Thankx in advance. -TareqThankx Rage for the quick reply. I didnt make the function static. That was the problem. Now it works fine but i have another problem. Can i access any objects declared in the mail dlg class? I have an edit box named _edit. if i use _edit.AppendText("blah blah"), it gives me the following error. :((
error C2228: left of '.AppendText' must have class/struct/union type
Thankx again for your response. -Tareq -
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h_beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... }
Any help/pointer will be very helpful. Thankx in advance. -Tareq1. modify your ThreadFunc like this:
void ThreadFunc(void * dummy)
2. call _beginthread like this:_beginthread(ThreadFunc, 0, this);
3. again, modify your ThreadFunc to call a member function of your CMainDlg:void ThreadFunc(void * dummy)
{
CMainDlg* m_pDlg = (CMainDlg*)dummy;
if(m_pDlg != NULL)
m_pDlg->ThreadFunc(NULL);
}regards
-
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h_beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... }
Any help/pointer will be very helpful. Thankx in advance. -TareqHi, Your thread ThreadFunc is CMainDlg mamber. To use CRT _beginthread try to declare it as separate function as: void ThreadFunc(void * dummy) { } Or try to use AfxBeginThread, or CreateThread Hope it help. Vitali
-
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h_beginthread(ThreadFunc, 0, NULL); ... void CMainDlg::ThreadFunc(void * dummy) { ... }
Any help/pointer will be very helpful. Thankx in advance. -TareqThank you all for your replys. Greg S. your solution worked like a charm and its so obvious ... i only forgot to cast it to the editor pointer inside the thread function. :D ... again thank you all for your solutions. -Tareq
-
Thankx Rage for the quick reply. I didnt make the function static. That was the problem. Now it works fine but i have another problem. Can i access any objects declared in the mail dlg class? I have an edit box named _edit. if i use _edit.AppendText("blah blah"), it gives me the following error. :((
error C2228: left of '.AppendText' must have class/struct/union type
Thankx again for your response. -TareqYou're inside a static function of a class - therefor you can't access member functions. Typically what people do is pass in a application variable to the thread's void* argument. In your case, this would be a pointer to the instance of your Dialog class. then you could refernece it. However with that solved your next problem will arise in making changes to UI controls from outside the main UI thread of execution. You must be very careful when doing this or risk causing lock, or various other wicked and evil things to happen. To simplify this, you might consider Posting a message back to your dialog class instance and then accessing the control there. This way you ensure that you're back in the context of the main UI thread. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!