[Solved] Connecting to OpenOffice C++
Posted: Wed Sep 23, 2009 3:09 pm
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/wik ... stallation
Next I started to write my application using the following guide.
http://wiki.services.openoffice.org/wik ... rogramming
The problem I'm having is that I can't "connect" to OpenOffice.
Below is my connection code (copied from the example).
Basically its getting as far as:
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.
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::registry::InvalidRegistryException at memory location 0x0012faf0..
First-chance exception at 0x7c812afb in OOOExample.exe: Microsoft C++ exception: com::sun::registry::InvalidRegistryException at memory location 0x0012faf0..
Thanks
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/wik ... stallation
Next I started to write my application using the following guide.
http://wiki.services.openoffice.org/wik ... rogramming
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
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;
}
Code: Select all
// instantiate a sample service with the servicemanager.
Reference< XInterface > rInstance = rServiceManager->createInstanceWithContext(
OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver" ),rComponentContext );
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
// create the initial component context
Reference< XComponentContext > rComponentContext =
defaultBootstrap_InitialComponentContext();
First-chance exception at 0x7c812afb in OOOExample.exe: Microsoft C++ exception: com::sun::registry::InvalidRegistryException at memory location 0x0012faf0..
First-chance exception at 0x7c812afb in OOOExample.exe: Microsoft C++ exception: com::sun::registry::InvalidRegistryException at memory location 0x0012faf0..
Thanks