Hi Frank,

the simple bootstrap mechanism is also available for C++ and laoading a document readonly is easy as well. When you have compiled the code below rename your binary "myexample[.exe]" to "_myexample[.exe]" and copy the "unoapploader[.exe] binary from the SDK in the same directory and rename it to "myexample[.exe]"

myexample -> _myexample
unoapploader -> myexample

two binaries in the same directory
.../myeample
.../_myexample

Start simply "myexample" and everything should work as expected. The bootstrap call starts your default office automatically or connect if it is already running. The connection is done via a named pipe.

Juergen

##########
...

using namespace std;
using namespace rtl;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::frame;


int SAL_CALL main( int argc, char **argv )
{
  try
  {
    // get the remote office component context
    Reference< XComponentContext > xContext(::cppu::bootstrap());
    if ( !xContext.is() )
    {
      cerr << "no component context!\n";
      return EXIT_FAILURE;
    }

    // get the remote office service manager
    Reference< XMultiComponentFactory > xServiceManager(
        xContext->getServiceManager());
    if ( !xServiceManager.is() )
    {
      cerr << "no service manager!\n";
      return EXIT_FAILURE;
    }

    // get an instance of the remote office desktop UNO service
    // and query the XComponentLoader interface
    Reference < XComponentLoader > xComponentLoader(
        xServiceManager->createInstanceWithContext(
            OUString( RTL_CONSTASCII_USTRINGPARAM(
                "com.sun.star.frame.Desktop")),
            xContext), UNO_QUERY_THROW);

    Sequence < ::com::sun::star::beans::PropertyValue > props(1);
    props[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
    props[0].Value = Any(true);

    // open a spreadsheet document
    Reference< XComponent > xComponent(
        xComponentLoader->loadComponentFromURL(
            "<your_fileurl>",
            OUString(RTL_CONSTASCII_USTRINGPARAM( "_blank" )), 0,
            props));
    if ( !xComponent.is() )
    {
       cerr << "opening spreadsheet document failed!\n";
       return EXIT_FAILURE;
    }
 }
 catch ( ::cppu::BootstrapException & e )
 {
    cerr << "caught BootstrapException: "
         << OUStringToOString(e.getMessage(),
                RTL_TEXTENCODING_ASCII_US ).getStr()
         << '\n';
    return EXIT_FAILURE;
 }
 catch ( Exception & e )
 {
    cerr << "caught UNO exception: "
         << OUStringToOString(e.Message,
                RTL_TEXTENCODING_ASCII_US ).getStr()
         << '\n';
    return EXIT_FAILURE;
 }

 return EXIT_SUCCESS;
}
######


frank111981 wrote:
In a C or C++ program I have to open a open Office document to show it to the
user in read only way. I hope that there is an API function that can help me
by calling the Open Office suite and open the file but I don't find it.
Could you help me?
If you know a solution to do that in Java it can be useful anyway.

Thanks a lot
Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to