Sorry if this question is reported into more posts.
But I have difficulty managing more concept…
to VB.net 2019 I have open with success a document with this code:
Imports unoidl.com.sun.star.lang
Imports unoidl.com.sun.star.uno
Imports unoidl.com.sun.star.bridge
Imports uno.util
Imports unoidl.com.sun.star.beans
Imports unoidl.com.sun.star.util
Imports unoidl.com.sun.star.container
Private oSM, oDesk, oDoc As Object
Private oFrame As Object
public sub OpenDocument()
Dim oDocProps As Object
oSM = CreateObject("com.sun.star.ServiceManager")
oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
Dim arProps() As unoidl.com.sun.star.beans.PropertyValue = New unoidl.com.sun.star.beans.PropertyValue() {}
Dim arg(0)
Dim url As String = "private:factory/swriter"
oDoc = oDesk.loadComponentFromURL(url, "_blank", 0, arg)
oFrame = oDoc.getCurrentController().getFrame()
Console.WriteLine(oFrame.Title)
_StatoControllo.CosaCercareTraProcessi = oFrame.Title
oDocProps = oDoc.getDocumentProperties()
Console.WriteLine(oDocProps.Title)
End sub
Now I have read many posts for Intercept onClose event
in this link
he proposes this code:
Dim xContainer As XContainer = REM # TODO: Get object you want to listen to
Dim myListener As MyListener = New MyListener()
xContainer.addContainerListener(myListener)
and more:
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
the problem remain this row:
Dim xContainer As XContainer = REM # TODO: Get object you want to listen to
if I insert oDoc or oFrame receive ever message error
if i insert
Dim xContainer As XContainer = DirectCast(oDoc, XDocumentEventBroadcaster)
i have this error: “XDocumentEventBroadcaster not defined”
VB suggests me to write
Dim xContainer As XContainer = DirectCast(oDoc, unoidl.com.sun.star.document.XDocumentEventBroadcaster)
But if I run application i have this error:
System.InvalidCastException:
‘Impossibile eseguire il cast di
oggetti COM di tipo
‘System.__ComObject’ in tipi di
interfaccia
‘unoidl.com.sun.star.document.XDocumentEventBroadcaster’.
L’operazione non è stata completata
perché la chiamata QueryInterface sul
componente COM per l’interfaccia con
IID
‘{5E6E43A6-4127-392D-8186-CFABE7507E7A}’
non è riuscita a causa del seguente
errore: Interfaccia non supportata.
(Eccezione da HRESULT: 0x80004002
(E_NOINTERFACE)).’
why is so extremly difficulty?
more link:
https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=67742