How to correctly add Presentation listener to macro?

I want to add a presentation listener to a macro in LibreOffice 4.2.6.3 for Impress.
This is the basic code so far:


Option Explicit
Global oDoc
Global oPresentation
Global oController	
Global oListener
Sub addListener
       oDoc=ThisComponent
       oPresentation=oDoc.Presentation
       oListener=createUnoListener("test_","com.sun.star.presentation.XSlideShowListener")
       Presentation.start()
       oController=oPresentation.Controller
       oController.addEventListener(oListener)
end sub

In addition i have added implementations for the listener methods with the “test_” prefix".

This gives me the error “Object variable not set.” for oController. Using “oController=oPresentation.getController()”
gives the same error. oController=ThisComponent.getCurrentController() works however, but this gives me a “DrawController”. This does not seem like the correct controller for a presetation, as only the method “disposing” is called when going through the presentation.How do I make the above code work?

Hi - I do not know if this is a copying error, but you use

Presentation.start () 

while you set

Global oPresentation

Also I think you should use the method addSlideShowListener. See the ListenerImpress.odp

Finally a tip: I’m not sure Impress manipulation program is very stable …

I also had the problem reported by miktoki, and pierre-yves’ example produced the same error. Adding a wait statement (Wait 100) before the addSlideShowListener fixed it.
But where are the print messages going to appear? I’m not seeing them.