Bug 158557 - I am trying to use COM on Windows to load an OpenOffice Writer object in a window but it fails
Summary: I am trying to use COM on Windows to load an OpenOffice Writer object in a wi...
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-06 00:02 UTC by Robert Goodman
Modified: 2024-03-05 23:14 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Goodman 2023-12-06 00:02:26 UTC
Description:
I am embedding a new LibreOffice text document in another window, but it fails. After building LibreOffice... I discovered that the code that creates class factories for creating the various LibreOffice objects, immediately deletes them...

app.cxx line 1917

1917 xSMgr->createInstance("com.sun.star.bridge.OleApplicationRegistration");
1918 xSMgr->createInstance("com.sun.star.comp.ole.EmbedServer");

the assembly code is
    xSMgr->createInstance("com.sun.star.bridge.OleApplicationRegistration");
5B148004  lea         edx,[xSMgr]  
5B148007  push        edx  
5B148008  call        com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory>::operator-> (5B13DCC0h)  
5B14800D  add         esp,4  
5B148010  mov         dword ptr [ebp-20h],eax  
5B148013  mov         eax,dword ptr [ebp-20h]  
5B148016  mov         ecx,dword ptr [eax]  
5B148018  mov         edx,dword ptr [ecx+0Ch]  
5B14801B  mov         dword ptr [ebp-48h],edx  
5B14801E  movzx       eax,byte ptr [ebp-0Fh]  
5B148022  push        eax  
5B148023  push        5B25AC88h  
5B148028  lea         ecx,[ebp-24h]  
5B14802B  call        rtl::OUString::OUString<char const [47]> (5B1321F0h)  
5B148030  mov         byte ptr [ebp-4],2  
5B148034  lea         ecx,[ebp-24h]  
5B148037  push        ecx  
5B148038  lea         edx,[ebp-4Ch]  
5B14803B  push        edx  
5B14803C  mov         eax,dword ptr [ebp-20h]  
5B14803F  push        eax  
5B148040  call        dword ptr [ebp-48h]  
5B148043  add         esp,0Ch  
5B148046  lea         ecx,[ebp-4Ch]  
5B148049  call        com::sun::star::uno::Reference<com::sun::star::uno::XInterface>::~Reference<com::sun::star::uno::XInterface> (5B13BFC0h)  
5B14804E  mov         byte ptr [ebp-4],1  
5B148052  lea         ecx,[ebp-24h]  
5B148055  call        rtl::OUString::~OUString (5B13CED0h)  

Since this code never gets called again, attempts to create COM objects time out because the class factory is missing.

Steps to Reproduce:
1.Try to embed a Libre Office object using COM
2.
3.

Actual Results:
The code times out and Windows gives an error

Expected Results:
It should display the new document in the window


Reproducible: Always


User Profile Reset: No

Additional Info:
let me know what this is fixed (bgoodman2@opentext.com)
Comment 1 Mike Kaganski 2023-12-06 12:08:50 UTC
The code you see indeed automatically destroys the temporaries created by calls to createInstance. However, that is expected, and the calls are only intended to *register the servers in registry*, as e.g. made in commit afe1abd5aab0298f15e142094475f15355217b69.

To see if there's some actual problem in this code, a reproducer is needed; it would be best, if that would be some script like VBS, which would allow to repro without setting up some environment and build some application for the task.

Thank you!
Comment 2 Robert Goodman 2023-12-06 16:41:04 UTC
When I run the LibreOffice code (compiled using Dev Studio 2019), it immediately destroys and unregisters the classes.. It winds up here:

Lines 74- 81 servproc.cxx

EmbedServer_Impl::~EmbedServer_Impl()
{
    for( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
    {
        if ( m_pOLEFactories[nInd] )
            m_pOLEFactories[nInd]->deregisterClass();
    }
}

Lines 128 - 133

bool EmbedProviderFactory_Impl::deregisterClass()
{
    HRESULT hresult = CoRevokeClassObject( m_factoryHandle );

    return (hresult == NOERROR);
}

CoRevokeClassObject removes the listener so COM doesn't work.. This code never gets called again so COM is essentially broken.

I tried my code using the current OpenOffice build and it works... but I can't find where the difference between OpenOffice code and LibreOffice code is in this area.

Unfortunately my code is embedded in a larger program but it essentially comes down to:

hResult = CoCreateInstance(
			ClassId,
			0,
                       CLSCTX_LOCAL_SERVER ,
	               IID_IUnknown,						 
                       (VOID**)&pUnknown );

where ClassId is equal to your OID_WriterOASISTextServer. My code times out and returns an error.
Comment 3 Buovjaga 2024-01-16 17:07:57 UTC
(In reply to Robert Goodman from comment #2)
> I tried my code using the current OpenOffice build and it works... but I
> can't find where the difference between OpenOffice code and LibreOffice code
> is in this area.

If you are unable to provide a minimal example for others to test, it is still possible for you to investigate this further on your own. We provide git repositories per each version of LibreOffice, each containing several thousands of runnable LibreOffices. They allow you to pinpoint where some behaviour appeared.

https://wiki.documentfoundation.org/QA/Bibisect
https://wiki.documentfoundation.org/QA/Bibisect/Windows

As a first step, you might consider getting the Windows "releases" repository to narrow down the initial search. The older LibreOffice versions do require older versions of Microsoft Visual C++ runtimes to be present (x86).

Let me know, if you need help with the process and I can guide you.
Comment 4 Robert Goodman 2024-01-16 18:52:15 UTC
all I need to do is:

hResult = CoCreateInstance(
			OID_WriterOASISTextServer,
			0,
                       CLSCTX_LOCAL_SERVER ,
	               IID_IUnknown,						 
                       (VOID**)&pUnknown );
 
and it fails.

I built the latest LibreOffice from the current source files and got the result I reported.
Comment 5 Robert Goodman 2024-03-05 23:14:14 UTC
In regards to the statement:
"the calls are only intended to *register the servers in registry*" is false.. Windows requires that the servers be active to handle COM calls while LibreOffice is running. 
They can't be taken down until you close LibreOffice.