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. call event of Activex in thread procedure!

call event of Activex in thread procedure!

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

    I create a ActiveX project in Visual C6 , in this Activex I create a thread with use createthread function , now I want call a event of Activex in inside createevent function, when I call event routine and use my ActiveX in VB or delphi , then I get one exception in run time ,.... Please help me. Thanks, Hamed.

    R H 2 Replies Last reply
    0
    • H hameduser

      I create a ActiveX project in Visual C6 , in this Activex I create a thread with use createthread function , now I want call a event of Activex in inside createevent function, when I call event routine and use my ActiveX in VB or delphi , then I get one exception in run time ,.... Please help me. Thanks, Hamed.

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

      I don't fully understand what you're doing... :~ You "want to call an event of the ActiveX"... Does this mean you are calling a source interface implemented by the client, but defined in the ActiveX typelib, from the secondary thread in your ActiveX? ...or... Are you calling your ActiveX dispinterface from the client function called "createevent"?


      "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
      • H hameduser

        I create a ActiveX project in Visual C6 , in this Activex I create a thread with use createthread function , now I want call a event of Activex in inside createevent function, when I call event routine and use my ActiveX in VB or delphi , then I get one exception in run time ,.... Please help me. Thanks, Hamed.

        H Offline
        H Offline
        hameduser
        wrote on last edited by
        #3

        Hi Roger Stoltz, I create a thread in my ActiveX project with use createthread function : handleTH = CreateThread( NULL, // Thread Attributes 0, // Stack size CheckTinyThread, // Thread function this, // Thread parameter 0, // Default flags &dwThreadID // Thread ID ); in inside this function I call a even of ActoiveX : DWORD WINAPI CheckTThread (LPVOID lpParameter) { CMyCtrl *cMyc1 = (CMyCtrl*) lpParameter; while(TRUE) { if ( MT.Detect () == FALSE) { cTinyc1->FireTinyDisconnect(); // calling event of activex ExitThread(0); } } return 1; } build my project and use my ActiveX control in VB 6, my control works in IDE of VB correct, but make exe and run exe file ,when code event run get a exception Error.

        R 1 Reply Last reply
        0
        • H hameduser

          Hi Roger Stoltz, I create a thread in my ActiveX project with use createthread function : handleTH = CreateThread( NULL, // Thread Attributes 0, // Stack size CheckTinyThread, // Thread function this, // Thread parameter 0, // Default flags &dwThreadID // Thread ID ); in inside this function I call a even of ActoiveX : DWORD WINAPI CheckTThread (LPVOID lpParameter) { CMyCtrl *cMyc1 = (CMyCtrl*) lpParameter; while(TRUE) { if ( MT.Detect () == FALSE) { cTinyc1->FireTinyDisconnect(); // calling event of activex ExitThread(0); } } return 1; } build my project and use my ActiveX control in VB 6, my control works in IDE of VB correct, but make exe and run exe file ,when code event run get a exception Error.

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

          Ok, I interpret this as you spawn a thread inside your ActiveX component and try to fire an event from there. Your ActiveX is presumably running in an STA, Single Threaded Apartment. An STA can only have one single thread running inside it, if you create another thread you have to set up another apartment. This is done by calling ::CoInitialize[Ex]() in the thread. To be able to use the source interface you fire the events on you have to marshal that interface to the new apartment. Whenever you cross apartment boundaries with an interface you have to marshal the interface. This can be done with ::CoMarshalInterThreadInterfaceInStream() / ::CoGetInterfaceAndReleaseStream() or through the GIT (Global Interface Table). Have a look at Lim Bio Liong's article serie startnig here[^] for more info.


          "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
          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