AfxbeginThread
-
In an Mfc programm ( dialog based) i created a thread through the AfxBeginThread function . I need that the specific class that was created will get access to another class ( the main Dlg class)???? (i tried to use pointer but no good !) meirav
You should not pass dialog pointer to the thread because it may be invalid. I think you can use GetSafeHwnd() to get the handle of the main dialog and pass it to the thread. In the thread you can use FromHandle() to get back the main dialog pointer and then you can access the main dialog class. Here is an example: UINT ThreadProc(LPVOID);// the thread proc HWND hWnd; // for handle of main dialog BOOL C???Dlg::OnInitDialog() { ...// some codes hWnd=GetSafeHwnd(); ...// other codes } void C???Dlg::OnButton1() // Button1 is a sample button { AfxBeginThread(ThreadProc,NULL); } UINT ThreadProc(LPVOID lpData) { C???Dlg *pDlg=(C???Dlg*)C???Dlg::FromHandle(hWnd); // get the main dlg pointer ...// do what you want to do } You can also pass the handle through the thread proc's lpData pointer, then you don't have to declare the hWnd as a external variable.:) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.
-
In an Mfc programm ( dialog based) i created a thread through the AfxBeginThread function . I need that the specific class that was created will get access to another class ( the main Dlg class)???? (i tried to use pointer but no good !) meirav
Thank you for your answer, i tried what you suggest me , but there is one problem: when i pass the LPVOID to the ThreadProc (I did it on ThreadProc::InitInstance) using the debug i saw that he never get at all to this Function . (without the LPVOID it did get there ) it will be a great help if you can help me.
-
Thank you for your answer, i tried what you suggest me , but there is one problem: when i pass the LPVOID to the ThreadProc (I did it on ThreadProc::InitInstance) using the debug i saw that he never get at all to this Function . (without the LPVOID it did get there ) it will be a great help if you can help me.
Could you show me your codes? I think that would be a great help.;) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.
-
Could you show me your codes? I think that would be a great help.;) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.
-
Hi,I did exacly the code you suggested in your reply above. I can send the programm i did (it is very short ) if it is needed.
OK, you can either paste it or send it to my mailbox.:) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.