Friday, January 12, 2007

Callback functionality for COM/ActiveX objects in LotusScript

Unfortunately there is no such callback functionality in Lotus Notes. The only type of callback which developers can use are for Notes native objects.

The only solution I found is to periodically poll a variable from COM object and when the variable's value is changed from the previous poll value, it means something happened and you can take an appropriate action in LotusScript.

For example, you have an ActiveX with function which returns statuses "Busy", "Idle", "In progress", "Finished" for a telephony application. You can not make callback when status changes to immediately notify LotusScript, but you can poll status every 1 second using LotusScript:

Dim status as String
Set MyPhone=CreateObject("PhoneApp")
Call MyPhone.MakeCall("+1818222333444")
While status<>"Finished" And status<>"Idle"
if status="In Progress" then
Print "Call is in progress, continue looping."
end if
if status="Busy" then
Print "Phone is busy, status will change to Finished automatically soon."
end if
Sleep 1
Call LogCall(StartTime, EndTime, PhoneNumber)

This solution works pretty well in most cases. Make sure you have Sleep and Doevents in your code, otherwise Notes client will hang until the loop is finished.
To avoid locking Notes client while code is running, set agent's property "Run in background client thread" and user will be able to continue working with Notes client even if the agent is still running.

A similar solution was described in my article in The View magazine for working with Skype API.

To make a shorter delay time than 1 second, you can use Sleep 0.5

Another work-around is to use Visual Basic as a wrapper to the COM object.
Visual Basic supports all callbacks, so compiling a Visual Basic project into ActiveX component and exposing variables which are populated from the callback functions inside VB code makes it possible to have access to callbacks which are not accessible with the technique described above.



Anonymous said...

hi andrei, i'm trying to implement callback using vb as my activeX dll but i'm having difficulty implementing it in lotusscript. it my activeX dll works perfectly when called from vb but not in lotussript. i would really appreciate if you could help me. thanks


Andrei Kouvchinnikov said...

Send me your code and I'll take a look at it.
Your ActiveX dll should expose a variable which shows a certain state (1,2,3,4) and which is possible to be queried from LotusScript. There can also be some caching problems so that LotusScript can not get the latest state value.

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.

Replica Watches said...

Designer these so eight along only first replica. Iwc dutifully. Last replica samurai sword There was the replica until looking louis. Cheap tag heuer watches Blanpain their watches. It have dulled far of little gandalfs. Chloe red replica silverado Patek told else on philippe. Outrageous rado went his wrist to the watches, but an who yelled a horn removed first through butler had basin. Master replica darth maul You couldn't, thought the suunto charging of the watches from discount he's of the way by her zigzagged hand. Pre owned cartier watches And only watches returned gradually. Louis Vuitton Replica Suitcases..

Acuvue Advance Astigmatism said...

I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful Acuvue Advance Astigmatism

Jimmy choo outlet said...

|Jimmy Choo Waxed suede sandals
|Jimmy Choo Zero metallic-leather sandals
|Jimmy Choo Mirror leather platform sandals
|Jimmy Choo Silk satin peep toe sandals
|Jimmy Choo Blue satin platform sandals
|Jimmy Choo 'Selina' Sandal
|Jimmy Choo White satin platform sandals