Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CWinThread use

CWinThread use

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CDRAIN
    wrote on last edited by
    #1

    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.

    R B 2 Replies Last reply
    0
    • C CDRAIN

      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.

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • C CDRAIN

        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.

        B Offline
        B Offline
        bob16972
        wrote on last edited by
        #3

        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 }

        C 1 Reply Last reply
        0
        • B bob16972

          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 }

          C Offline
          C Offline
          CDRAIN
          wrote on last edited by
          #4

          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 grid thread->openGrid(&m_wndGrid,str,m_inUseSource); Close the thread is it right thread->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!!!!

          B 1 Reply Last reply
          0
          • C CDRAIN

            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 grid thread->openGrid(&m_wndGrid,str,m_inUseSource); Close the thread is it right thread->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!!!!

            B Offline
            B Offline
            bob16972
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups