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/com.sun.star.reflection.theCoreReflection" )
set xClass = xCoreReflection.forName( "com.sun.star.document.XEventBroadcaster" )
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.

Imports unoidl.com.sun.star.container
Imports unoidl.com.sun.star.lang

Module Module1
    Sub Main()
        Dim oSM
        Dim oDesk, oDoc As Object
        Dim arg(-1)
        oSM = CreateObject("com.sun.star.ServiceManager")
        oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
        oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
        oDoc.getText().setString("Hello!")
        Dim xContainer As XContainer =  REM # TODO: Get object you want to listen to
        Dim myListener As MyListener = New MyListener()
        xContainer.addContainerListener(myListener)
    End Sub
    Class MyListener
        Implements XContainerListener
        Sub disposing(oEvent As EventObject) Implements XEventListener.disposing
            MsgBox("disposing")
        End Sub
        Sub XContainerListener_elementInserted([Event] As ContainerEvent) Implements XContainerListener.elementInserted
            MsgBox("elementInserted")
        End Sub
        Sub XContainerListener_elementRemoved([Event] As ContainerEvent) Implements XContainerListener.elementRemoved
            MsgBox("elementRemoved")
        End Sub
        Sub XContainerListener_elementReplaced([Event] As ContainerEvent) Implements XContainerListener.elementReplaced
            MsgBox("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.

Thanks

@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.