Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Active-X created in C++ to expose a C library
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00902136
Message ID:
00902245
Views:
28
>You should NEVER fire an event across threads through a direct pointer. You must post the message to a queue window on the main control thread and have that make the fireevent call.
>
>i.e.
>
>-create window on main thread.
>-spawn worker thread
>-in worker thread sendmessage to window made on main thread
>-in window on main thread, fire the event.
>
>You will get data corruption and bunch of other issues by not doing it this way.


Brian, Thanks for your reply !

How would I do that in an acitvex that has no main ?

One of the functions of the class is called getMonitor()
this is a public method of the active x and it calls an internal protected member function called setMonitor() which makes function calls into a C library so that a Mitel switch can communicate with the ocx via the callback.
BOOL CVfpocxCtrl::setMonitor()
{


	int iRet = SXERR_FAIL;
	iRet = SXInit( SX_COMPACT_MESSAGING , NULL );


	//If its OK then show the about dialog
	if ( iRet != SX_OK ) 
	{ MessageBox( NULL , "SXInit returned NOT OK " ) ;}


	iRet = SXERR_FAIL;
	char charPBXIPAddress[40];
	strcpy( charPBXIPAddress , m_cPBXIpAddress );
	


     iRet = SXOpenPBX(SX_PBX_HANDLE_PTR, &hPBXObject ,
	     SX_PBX_IPADDRESS, charPBXIPAddress,
	     SX_COMMS_ERROR_PROC, this->callBackMitaiEvent,			  
	     SX_COMMS_ERROR_DATA_PTR, this,
	     NULL);

	this->setErrorText(iRet) ;
	if (iRet != SX_OK) { return false ; }

	
	iRet = SXMonitor ( &hMonitorHandle  ,  
		   SX_PBX_HANDLE, hPBXObject , 
		   SX_DN,	(LPCTSTR)m_cDNofExtensionToMonitor , 
		   NULL );

	this->setErrorText(iRet) ;
	if (iRet != SX_OK) { return false ; }

    iRet = SXSetCallback(SX_MONITOR_HANDLE, hMonitorHandle ,
	SX_EVENT , OnCallReceived ,
	SX_CALLBACK_PROC, this->callBackMitaiOnCallReceived ,
	SX_CALLBACK_DATA_PTR , this ,
	NULL);

}
this callback is also a member function of this class and I have the evnet firing in a new thread, is this enough protection or should the setMonitor member function be launched in a new thread ?
void CVfpocxCtrl::callBackMitaiOnCallReceived(SXEvent* pEvent , CVfpocxCtrl* pThis)
{

	int event_type = SX_EventType(pEvent);
	char* event_name = SXGetText ( SX_EVENT, event_type, NULL ) ;	
	char* state_name = SXGetText ( SX_STATE, SX_EventState(pEvent), NULL ) ;
	char* cause_name =  SXGetText ( SX_CALL_CAUSE, SX_EventCause(pEvent), NULL ) ;


	pThis->m_sxCallsInternalID = SX_EventCallId(pEvent);


	// Now the Caller device
	SXDevice * oDevice = SX_CallerDevice(pEvent) ;

	pThis->m_cCallerIDName =  SX_GetName(SX_DeviceName(oDevice)) ;
	pThis->m_cCallerIDFirstName = SX_GetFirstName(SX_DeviceName(oDevice)) ;
	pThis->m_cCallerIDMiddleName = SX_GetMiddleName(SX_DeviceName(oDevice)) ;
	pThis->m_cCallerIDLastName = SX_GetLastName(SX_DeviceName(oDevice)) ;
	
	SXDigits * cDNIS = SX_DeviceDNIS(oDevice) ;
	SXNumber * cANI = SX_DeviceANI(oDevice) ;
	pThis->m_cDNISDigits =  cDNIS->digits  ;
	pThis->m_cAniDigits = cANI->number  ;
         pThis->m_cMitaiEventCause = cause_name ;
         pThis->m_cMitaiEventName = event_name ;
         pThis->m_cMitaiEventState = state_name ;


	//Fire the event 
	//pThis->FireMitaiEvent() ;


       //	AfxBeginThread( fireTheMiTAiEvent , pThis);
	AfxBeginThread(fireTheMiTAiEvent,pThis,THREAD_PRIORITY_NORMAL,0,0,NULL);
	
	

}
Thanks !
Greg Foote
Software At Work, Inc.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform