Ky.
September 12th, 2007, 11:11 AM
Hi guys,
I´m not sure I am using the corect terminology, since I´m pretty new to MFC programming. Sorry for that.
I created an object of a wrapper-class from an OCX libray (included with class _myObjectClass : public COleDispatchDriver).
As opposed to other classes in this library and what "OCX" suggests, this one is non-visual (no ActiveX).
I can use this object in a function just fine, except for when calling the function from a thread.
This works fine:
void TestDlg::DoIt()
{
_myObject m_obj;
m_obj.CreateDispatch("xxxx.xxxx");
m_obj.ObjMethod(xxx);
}
void TestDlg::OnButton()
{
DoIt();
}
But this does not
static UINT MyThread(LPVOID p);
UINT TestDlg::MyThread(LPVOID p)
{
TestDlg * app=(TestDlg *) p;
app->DoIt();
return 0;
}
void TestDlg::DoIt()
{
_myObject m_obj;
m_obj.CreateDispatch("xxxx.xxxx");
m_obj.ObjMethod(xxx);
}
void TestDlg::OnButton()
{
AfxBeginThread(MyThread, this);
}
Can anyone explain that behaviour or even suggest a solution?
Any advice or idea is greatly appreciated.
Thanks in advance,
..ky.
P.S. I already implemented a version, where PostMessage from MyThread calls the DoIt function, instead of calling it directly. It works, but it blocks my dialogue while DoIt is executed. But I need to run methods of m_obj while the main thread does other things...
I´m not sure I am using the corect terminology, since I´m pretty new to MFC programming. Sorry for that.
I created an object of a wrapper-class from an OCX libray (included with class _myObjectClass : public COleDispatchDriver).
As opposed to other classes in this library and what "OCX" suggests, this one is non-visual (no ActiveX).
I can use this object in a function just fine, except for when calling the function from a thread.
This works fine:
void TestDlg::DoIt()
{
_myObject m_obj;
m_obj.CreateDispatch("xxxx.xxxx");
m_obj.ObjMethod(xxx);
}
void TestDlg::OnButton()
{
DoIt();
}
But this does not
static UINT MyThread(LPVOID p);
UINT TestDlg::MyThread(LPVOID p)
{
TestDlg * app=(TestDlg *) p;
app->DoIt();
return 0;
}
void TestDlg::DoIt()
{
_myObject m_obj;
m_obj.CreateDispatch("xxxx.xxxx");
m_obj.ObjMethod(xxx);
}
void TestDlg::OnButton()
{
AfxBeginThread(MyThread, this);
}
Can anyone explain that behaviour or even suggest a solution?
Any advice or idea is greatly appreciated.
Thanks in advance,
..ky.
P.S. I already implemented a version, where PostMessage from MyThread calls the DoIt function, instead of calling it directly. It works, but it blocks my dialogue while DoIt is executed. But I need to run methods of m_obj while the main thread does other things...