How do we import the listener events of LibreOffice writer in Visual Basic 6?

I am trying to implement a listener event in Visual Basic 6 for LibreOffice Writer. I was referred to the following code from Document Events - Apache OpenOffice Wiki.

set xContext = objServiceManager.getPropertyValue( "DefaultContext" )
set xCoreReflection = xContext.getValueByName( "/singletons/" )
set xClass = xCoreReflection.forName( "" )
set xMethod = xClass.getMethod( "addEventListener" )

dim invokeargs(0)
invokeargs(0) = myListener

set value = objServiceManager.Bridge_GetValueObject()
call value.InitInOutParam("[]any", invokeargs)
call xMethod.invoke( objDocument, value )

I am not able to understand the implementation of the listener event from this code.

Can I get example code to implement listener events for LibreOffice Writer in Visual Basic 6?

This was originally asked at vb6 - How do we import the listener events of LibreOffice Writer in Visual Basic 6 - Stack Overflow.

Here is more complete VB.NET code. Probably won’t work in VB6 though.


Module Module1
    Sub Main()
        Dim oSM
        Dim oDesk, oDoc As Object
        Dim arg(-1)
        oSM = CreateObject("")
        oDesk = oSM.createInstance("")
        oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
        Dim xContainer As XContainer =  REM # TODO: Get object you want to listen to
        Dim myListener As MyListener = New MyListener()
    End Sub
    Class MyListener
        Implements XContainerListener
        Sub disposing(oEvent As EventObject) Implements XEventListener.disposing
        End Sub
        Sub XContainerListener_elementInserted([Event] As ContainerEvent) Implements XContainerListener.elementInserted
        End Sub
        Sub XContainerListener_elementRemoved([Event] As ContainerEvent) Implements XContainerListener.elementRemoved
        End Sub
        Sub XContainerListener_elementReplaced([Event] As ContainerEvent) Implements XContainerListener.elementReplaced
        End Sub
    End Class
End Module

Hi Jim,

Please let me know how to get object and assign for container.

Dim xContainer As XContainer = REM # TODO: Get object you want to listen to

Also provide me some example code (C# or VB.NET) to raise onSave event for libreoffice document.


@Muru1: Please ask this as a separate question, and I will give an answer for C# (which I prefer instead of VB.NET). Since this will be your first question on this site, have a look at my suggested list at Guidelines for asking. Especially be sure not to check the community wiki box. Then if your question is good enough, I’ll upvote it to give you some reputation points, and you’ll get points if you mark the answer as correct.