Question about AfxBeginThread(...)
-
Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian
-
Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian
try this please
void CMyAnswer::RunThread() { CWinThread* m_Thread; m_Thread=AfxBeginThread ( MyThread, this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); if (m_Thread != NULL) m_Thread->ResumeThread(); } UINT MyThread( LPVOID pv ) { CMyAnswer* m_Answer = (CMyAnswer*) pv; m_Answer->Modify(); return 0; } void CMyAnswer::Modify() { }
_**
**_
WhiteSky
-
Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian
If you're using managed objects, I recommend you use managed threads - delegates. It makes life a bit easier.
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
try this please
void CMyAnswer::RunThread() { CWinThread* m_Thread; m_Thread=AfxBeginThread ( MyThread, this,THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); if (m_Thread != NULL) m_Thread->ResumeThread(); } UINT MyThread( LPVOID pv ) { CMyAnswer* m_Answer = (CMyAnswer*) pv; m_Answer->Modify(); return 0; } void CMyAnswer::Modify() { }
_**
**_
WhiteSky
-
If you're using managed objects, I recommend you use managed threads - delegates. It makes life a bit easier.
Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Hello! I need to have a thread that can modify a Form.. I tried passing a form pointer as a param, but AfxBeginThread(...,LPVOID) says it cannot convert from Form1 __gc* to LPVOID. And I cannot make a unmanaged structure that contains a Form*.. How can I overcome this problem? Alin Stoian
You need to pin a managed object in order to get a raw pointer to it.
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ