|
-
September 27th, 1999, 01:37 PM
#1
[HELP] using class member data in worker Thread??
Hi:
I declare a class..
class CMyClass
{
void function_name();
data_type member_name;
...
}
//and its implementation
CMyClass::function_name()
{ ...
AfxBeginThread(ThreadFunc,this);
...
}
UINT ThreadFunc(LPVOID pParam)
{
CMyClass* my_class=(CMyClass*)pParam;
my_class->mamber_name->func();
// I found problems when using the member data of CMyClass
// for example: if the member data is IWebBrowser2* m_Web;
// and when I call IWebBrowser2->QueryInterface(IID_IHTMLDocuement2,(void**) &pDoc) in the thread function,
// it must be failed!!
}
I dont know how to use this kind of member data when using worker thread
especially the functions provided by these member data of declared class object.
if there any good method to make it?
any response will be great appreciated!!
-
September 27th, 1999, 04:25 PM
#2
Re: [HELP] using class member data in worker Thread??
I don't know anything about the IWebBrowser thing, but when I was doing some worker thread stuff I read that it is risky to do anything too fancy in the thread, especially UI things (like drawing). Things might work better if you send messages from the thread to do what you want, rather than calling functions.
-
September 28th, 1999, 07:48 AM
#3
Re: [HELP] using class member data in worker Thread??
Hi,
i don't know anything about threading and COM but i know that for MFC objects it is not recommended to share them between threads because MFC uses TLS memory to store message mapping data...Thus recommended communication is via Window messages.
Tomaz
-
September 29th, 1999, 07:51 AM
#4
Re: [HELP] using class member data in worker Thread??
Hi,
I just read some articles about the apartment models. I am a begginer in COM but I think what you need to do with your thread is to enter an apartment on top of it and demarshall interface pointer after call to query interface.
Might be completely wrong since my understanding of apartments is still vogue but on the following address you will find examples of threads using interfaces, passed as parameters.
http://www.vcdj.com/magazine/febmag99/comapt1.asp,
http://www.vcdj.com/magazine/aprmag99/comapt21.asp
Hope it helps,
Tomaz
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|