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. Threads and windowless ActiveX controls

Threads and windowless ActiveX controls

Scheduled Pinned Locked Moved C / C++ / MFC
questioncom
4 Posts 4 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.
  • B Offline
    B Offline
    BadJerry
    wrote on last edited by
    #1

    In a method of an OCX, I start a thread. I want to fire an event of the control at the end of the thread. How can I start this event in the thread of the OCX? I cannot do a PostMessage because the control is not a window. It seems to be an overkill to create a hidden window that would allow me to do so... Any idea?

    M I P 3 Replies Last reply
    0
    • B BadJerry

      In a method of an OCX, I start a thread. I want to fire an event of the control at the end of the thread. How can I start this event in the thread of the OCX? I cannot do a PostMessage because the control is not a window. It seems to be an overkill to create a hidden window that would allow me to do so... Any idea?

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      I suspect this is a question to be answered in the COM forum. I think you should be able to marshal the pointer to the container's callback interface across to your worker thread, and then call it from there. COM should have created a proxy object for the thread which can perform the appropriate marshalling to get back onto the UI thread. Look up CoMarshalInterThreadInterfaceInStream and the counterpart, CoGetInterfaceAndReleaseStream. Note that I'm only guessing - I've never done this.

      1 Reply Last reply
      0
      • B BadJerry

        In a method of an OCX, I start a thread. I want to fire an event of the control at the end of the thread. How can I start this event in the thread of the OCX? I cannot do a PostMessage because the control is not a window. It seems to be an overkill to create a hidden window that would allow me to do so... Any idea?

        I Offline
        I Offline
        igor1960
        wrote on last edited by
        #3

        . I want to fire an event of the control at the end of the thread If you really want to fire an event at the end of the thread, then it would be easier to just save args of your events and fire them on your main thread after secondary thread has finished. Alternatively, of course you can use interface pointer marshaling and or GIT, however you will be faced then again with troubles of thread sync, because your windowless activeX doesn't have it's own message pump. Therefore, I would suggest going with the hidden window, and I don't think it's overkill compared with interface pointer marshaling... "...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..." Me

        1 Reply Last reply
        0
        • B BadJerry

          In a method of an OCX, I start a thread. I want to fire an event of the control at the end of the thread. How can I start this event in the thread of the OCX? I cannot do a PostMessage because the control is not a window. It seems to be an overkill to create a hidden window that would allow me to do so... Any idea?

          P Offline
          P Offline
          Peter Molnar
          wrote on last edited by
          #4

          If you wanna fire an event at the end of your worker thread then the best thing is to monitor your thread execution status with GetExitCodeThread and fire the event directly from your control class. In order to do this you have to set the thread's autodelete member to FALSE. This should do the job:

          CWinThread* pThread = AfxBeginThread(...,CREATE_SUSPENDED);
          pThread->m_bAutoDelete = FALSE;
          pThread->ResumeThread();

          DWORD dwExitCode;

          while (TRUE)
          {
          GetExitCodeThread(pThread->m_hThread, dwExitCode);
          if (dwExitCode != STILL_ACTIVE)
          {
          FireYourEvent();
          break;
          }
          else
          SleepABitAndPumpMessages();
          }

          Peter Molnar

          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