AfxBeginThread() ???
-
Hi i want to write a simple thread , that will work in the background and i'll be able to do other things in my program until the thread is in progress,i do the following but get an error. UINT CtestDlg::MyThreadProc(LPVOID pParam)//create thread { for(int i=0;i<10000;i++) for(int j=0;j<10000;j++) {}; MessageBox("Finished"); return 0; } then call it : AfxBeginThread(MyThreadProc,0); but i get an error : c:\...\ : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'UINT (LPVOID)' Can anyone help ? Regards Giorgi Moniava
-
Hi i want to write a simple thread , that will work in the background and i'll be able to do other things in my program until the thread is in progress,i do the following but get an error. UINT CtestDlg::MyThreadProc(LPVOID pParam)//create thread { for(int i=0;i<10000;i++) for(int j=0;j<10000;j++) {}; MessageBox("Finished"); return 0; } then call it : AfxBeginThread(MyThreadProc,0); but i get an error : c:\...\ : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'UINT (LPVOID)' Can anyone help ? Regards Giorgi Moniava
See the FAQ 6.1 Why can't I use a member function as a callback?[^] --Mike-- LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Strange things are afoot at the U+004B U+20DD
-
Hi i want to write a simple thread , that will work in the background and i'll be able to do other things in my program until the thread is in progress,i do the following but get an error. UINT CtestDlg::MyThreadProc(LPVOID pParam)//create thread { for(int i=0;i<10000;i++) for(int j=0;j<10000;j++) {}; MessageBox("Finished"); return 0; } then call it : AfxBeginThread(MyThreadProc,0); but i get an error : c:\...\ : error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'UINT (LPVOID)' Can anyone help ? Regards Giorgi Moniava
use: AfxBeginThread(&MyThreadProc, (LPVOID)this, THREAD_PRIORITY_NORMAL); inside MyThreadProc you can add the code: CtestDlg *pTestDlg = (CtestDlg *)pParam; ... this will allow you to access any CtestDlg members.
-
use: AfxBeginThread(&MyThreadProc, (LPVOID)this, THREAD_PRIORITY_NORMAL); inside MyThreadProc you can add the code: CtestDlg *pTestDlg = (CtestDlg *)pParam; ... this will allow you to access any CtestDlg members.
-
Thanks Greg for you attention , but when i type : AfxBeginThread(&MyThreadProc,(LPVOID)this,0); i get an error : c:\..\: error C2276: '&' : illegal operation on bound member function expression Regards m0n0
Your MyThreadProc need to be static. And you only need to call like AfxBeginThread(MyThreadProc,(LPVOID)this,0); E.g CWinThread* pThread = AfxBeginThread (ThreadFunc, lpVoid, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED); ASSERT (NULL != pThread); pThread->m_bAutoDelete = FALSE; pThread->ResumeThread (); By the way, make sure you protect the variables that you are accessing in the 'this ' in the thread by using those synchronization classes like CMutex, Interlock functions and etc. Sonork 100.41263:Anthony_Yio