Page 1 of 1

[Solved] Connecting to OpenOffice C++

PostPosted: Wed Sep 23, 2009 3:09 pm
by rjparkin
Hello

I'm writing a C++ Windows application that edits the contents of an OpenOffice (3.1) spreadsheet.

I started off by downloading and installing the SDK using the following guide.

http://wiki.services.openoffice.org/wiki/SDKInstallation

Next I started to write my application using the following guide.

http://wiki.services.openoffice.org/wiki/Calc/API/Programming

The problem I'm having is that I can't "connect" to OpenOffice.

Below is my connection code (copied from the example).

Code: Select all   Expand viewCollapse view
Reference< XMultiServiceFactory > ooConnect(){
   // create the initial component context
   Reference< XComponentContext > rComponentContext =
            defaultBootstrap_InitialComponentContext();

   // retrieve the servicemanager from the context
   Reference< XMultiComponentFactory > rServiceManager =
            rComponentContext->getServiceManager();
 

   // instantiate a sample service with the servicemanager.
   Reference< XInterface > rInstance =  rServiceManager->createInstanceWithContext(
         OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver" ),rComponentContext );

   // Query for the XUnoUrlResolver interface
   Reference< XUnoUrlResolver > rResolver( rInstance, UNO_QUERY );
   if( ! rResolver.is() ){
      printf( "Error: Couldn't instantiate com.sun.star.bridge.UnoUrlResolver service\n" );
      return NULL;
   }
   try {
      // resolve the uno-url
      rInstance = rResolver->resolve( OUString::createFromAscii(
         "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" ) );

      if( ! rInstance.is() ){
         printf( "StarOffice.ServiceManager is not exported from remote counterpart\n" );
         return NULL;
      }

      // query for the simpler XMultiServiceFactory interface, sufficient for scripting
      Reference< XMultiServiceFactory > rOfficeServiceManager (rInstance, UNO_QUERY);

      if( ! rOfficeServiceManager.is() ){
            printf( "XMultiServiceFactory interface is not exported for StarOffice.ServiceManager\n" );
            return NULL;
        }       
        return rOfficeServiceManager;
   }
   catch( Exception &e ){
      OString o = OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US );
      printf( "Error: %s\n", o.pData->buffer );
      return NULL;
   }
   return NULL;
}


Basically its getting as far as:

Code: Select all   Expand viewCollapse view
// instantiate a sample service with the servicemanager.
   Reference< XInterface > rInstance =  rServiceManager->createInstanceWithContext(
         OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver" ),rComponentContext );


The function returns an empty handle and the connect function returns. Does anyone have any ideas as to why this happens or if I'm doing something completely wrong.

Does this have something to do with the .rdb files?

Its also possible that the problem could be related to the following function call.

Code: Select all   Expand viewCollapse view
   // create the initial component context
Reference< XComponentContext > rComponentContext =
       defaultBootstrap_InitialComponentContext();


After calling this piece of code I get the following messages in the Visual Studio output window.

First-chance exception at 0x7c812afb in OOOExample.exe: Microsoft C++ exception: com::sun::star::registry::InvalidRegistryException at memory location 0x0012faf0..
First-chance exception at 0x7c812afb in OOOExample.exe: Microsoft C++ exception: com::sun::star::registry::InvalidRegistryException at memory location 0x0012faf0..


Thanks

Re: Connecting to OpenOffice C++

PostPosted: Thu Sep 24, 2009 10:25 am
by rjparkin
I asked the same question on another forum and found my answer.

http://www.oooforum.org/forum/viewtopic.phtml?t=89285

Re: Connecting to OpenOffice C++

PostPosted: Mon Oct 15, 2018 2:21 pm
by Hel
Hello,

No longer solved.
I have the same problem. But the link from rjparkin to solve the problem does not work anymore.
So could you please send the solution or a working link?

That would be great :) Thanks