CWinThread use
-
I need to call ActiveX function from a thread so while it elaborate my app can go on. I made my CMyThread class derived from CWinThread class, in which I and create the thread in my app when I need to call the ActiveX functions. I have some problem: 1. In code when I need to create the Thread attach this code:
CMyThread * thread = AfxBeginThread(RUNTIME_CLASS(C4Thread));
but at compile-time it said "It's impossible to convert from 'CWinThread *' to 'CMyThread *'. WHY this? 2. In which method of my CMyThread class I must put the code to peform (the call to the ActiveX functions) or I need to implement a new function? In thi case how? Thanks a lot. -
I need to call ActiveX function from a thread so while it elaborate my app can go on. I made my CMyThread class derived from CWinThread class, in which I and create the thread in my app when I need to call the ActiveX functions. I have some problem: 1. In code when I need to create the Thread attach this code:
CMyThread * thread = AfxBeginThread(RUNTIME_CLASS(C4Thread));
but at compile-time it said "It's impossible to convert from 'CWinThread *' to 'CMyThread *'. WHY this? 2. In which method of my CMyThread class I must put the code to peform (the call to the ActiveX functions) or I need to implement a new function? In thi case how? Thanks a lot.A little out of context: see this thread[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
I need to call ActiveX function from a thread so while it elaborate my app can go on. I made my CMyThread class derived from CWinThread class, in which I and create the thread in my app when I need to call the ActiveX functions. I have some problem: 1. In code when I need to create the Thread attach this code:
CMyThread * thread = AfxBeginThread(RUNTIME_CLASS(C4Thread));
but at compile-time it said "It's impossible to convert from 'CWinThread *' to 'CMyThread *'. WHY this? 2. In which method of my CMyThread class I must put the code to peform (the call to the ActiveX functions) or I need to implement a new function? In thi case how? Thanks a lot.For starters, you need something like this... CSomeThread* pThread=(CsomeThread*)AfxBeginThread(RUNTIME_CLASS(CSomeThread)); it's much more advisable to start the thread suspended so you can prep the thread before it takes off to do work... pThread=(CSomeThread*)AfxBeginThread(RUNTIME_CLASS(CSomeThread), THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); // Set up the thread members (if any) // Then call resume thread to let it loose pThread->ResumeThread(); However, you have a slight issue with what you are trying to do. As far as I know, most ActiveX controls (if not all) expect to have a parent container so they can feed off of it's ambient properties. There are many different types of COM objects and some aren't designed to need a container. If your COM object is indeed an ActiveX control, it will likely need some sort of container to appease it. If I need to get the functionality of an ActiveX control but don't necessarily want it to show itself, I create a dummy container for it... // Need a parent container window to host the ActiveX control. // Make it invisible and popup CWnd wndInvisible; CString sWndClass=AfxRegisterWndClass(0); if (wnd.CreateEx(0,sWndClass,NULL,WS_POPUP,CRect(),NULL,0)) { // Use the dummy CWnd as a container for the control }
-
For starters, you need something like this... CSomeThread* pThread=(CsomeThread*)AfxBeginThread(RUNTIME_CLASS(CSomeThread)); it's much more advisable to start the thread suspended so you can prep the thread before it takes off to do work... pThread=(CSomeThread*)AfxBeginThread(RUNTIME_CLASS(CSomeThread), THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED); // Set up the thread members (if any) // Then call resume thread to let it loose pThread->ResumeThread(); However, you have a slight issue with what you are trying to do. As far as I know, most ActiveX controls (if not all) expect to have a parent container so they can feed off of it's ambient properties. There are many different types of COM objects and some aren't designed to need a container. If your COM object is indeed an ActiveX control, it will likely need some sort of container to appease it. If I need to get the functionality of an ActiveX control but don't necessarily want it to show itself, I create a dummy container for it... // Need a parent container window to host the ActiveX control. // Make it invisible and popup CWnd wndInvisible; CString sWndClass=AfxRegisterWndClass(0); if (wnd.CreateEx(0,sWndClass,NULL,WS_POPUP,CRect(),NULL,0)) { // Use the dummy CWnd as a container for the control }
Sorry, I want to say that I try your second solution... I don't have access to the source code for the ActiveX, so I try the UI-Thread. I try to explain my problem: on my thread I must fill a grid control (the ActiveX) and while this i need to refresh a progress bar. This is the code I use: Start the thread in which I'll fill the grid
C4ThrGrid * thread = (C4ThrGrid *)AfxBeginThread(RUNTIME_CLASS(C4ThrGrid));
Call the thread's function that fill the gridthread->openGrid(&m_wndGrid,str,m_inUseSource);
Close the thread is it rightthread->PostThreadMessage(WM_QUIT, 0, 0);
Is it the right way to obtain what I need? Why at runtime when I create the thread appear a message box that said "Insufficent Memory" Help!!!! -
Sorry, I want to say that I try your second solution... I don't have access to the source code for the ActiveX, so I try the UI-Thread. I try to explain my problem: on my thread I must fill a grid control (the ActiveX) and while this i need to refresh a progress bar. This is the code I use: Start the thread in which I'll fill the grid
C4ThrGrid * thread = (C4ThrGrid *)AfxBeginThread(RUNTIME_CLASS(C4ThrGrid));
Call the thread's function that fill the gridthread->openGrid(&m_wndGrid,str,m_inUseSource);
Close the thread is it rightthread->PostThreadMessage(WM_QUIT, 0, 0);
Is it the right way to obtain what I need? Why at runtime when I create the thread appear a message box that said "Insufficent Memory" Help!!!!Wow, that was the exact same post, word for word, that you posted as a reply to Roger Stoltz yesterday Your response from yesterday[^] I see Mr. Stoltz has summed it all up by basically saying you may want to further investigate COM and threads before you go any further with this. I am starting to feel this way myself. Maybe give those topics some more research and it may seem easier the second time around. I hope that helps.