Click to See Complete Forum and Search --> : ThreadFun with activeX
gogogo
August 23rd, 2005, 01:55 AM
I open a dialog based project, and create a thread fun. Now I want to use a active component in the thread fun. Supposing the component is "Ctest",
how can I call it in the thread fun. I just know how to call Dialog's normal component. But the same way can't be used in the activeX component.
Please teach how to use a activeX in the thread fun. THX!
========================
UINT AlarmThread(LPVOID LParam)
{
ThreadInfo* pInfo1 = (ThreadInfo*) LParam;
CGigaEthernetCameraDlg* hWnd =
(CGigaEthernetCameraDlg*)CWnd::FromHandle(pInfo1->hWnd);
CEdit* edt = (CEdit*)hWnd->GetDlgItem(IDC_ALARM);
edt->SetDlgItemInt(1);
return 1 ;
}
Marc G
August 23rd, 2005, 01:28 PM
You shouldn't use MFC objects between threads.
Your thread should post messages to the control instead.
gogogo
August 23rd, 2005, 08:30 PM
Excuse me,
Question1: You shouldn't use MFC objects between threads. Why?
Question2: Your thread should post messages to the control instead.
What does this words mean? please describe it more detailed.
And how to do that?
I am rookie about programming. Please tell me reason and teach me the concept.Thank you very much!
Marc G
August 24th, 2005, 01:13 PM
Question1: You shouldn't use MFC objects between threads. Why?
Because the MFC classes like CEdit etc are not thread safe. In other words, the MFC library does not guarantee that synchronization is happening on data which means 2 threads might access the object at the same time, which is bad because it can lead to unpredictable results.
Question2: Your thread should post messages to the control instead. What does this words mean? please describe it more detailed. And how to do that?
Posting messages means posting windows messages like WM_SETTEXT to a message queue and returning immediately. This can be done with the PostMessage function. Sendmessage on the contrary will send the message and won't return until the windows message has been processed.
Alin
August 24th, 2005, 01:29 PM
Excuse me,
Question1: You shouldn't use MFC objects between threads. Why?
Question2: Your thread should post messages to the control instead.
What does this words mean? please describe it more detailed.
And how to do that?
I am rookie about programming. Please tell me reason and teach me the concept.Thank you very much!
see this (http://www.codeguru.com/forum/showthread.php?t=350757#thread) FAQ's. in the "Threads" sections there are a lot of answers. Take the time and read them.
Marc G
August 24th, 2005, 01:39 PM
[ moved thread ]
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.