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