Hello,

using OOo SDK 3.2, the attached C++ example of a manually created bridge
segfaults while accessing the instance of com.sun.star.frame.Desktop
(the last line in the test-function).

That is because

  bridge->getInstance ("StarOffice.ServiceManager")
        ->createInstanceWithContext ("com.sun.star.frame.Desktop")

apparently returns something broken.

The same example runs fine when I set LD_LIBRARY_PATH to the
"program"-directory of an Office 2.4-installation.


Now I have two questions:

Can someone reproduce it or is it just a problem with my machine?

Would it be wrong to link my application to the libraries of an older
office (i.e. 2.4) and then connect via TCP to a newer office (i.e. 3.2)
like in the example below?  That seems to work but I don't want to
produce undefined behaviour.


Regards,
Denis


//-------------- code -------------------------------------//

#include <iostream>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/bridge/XBridgeFactory.hpp>
#include <com/sun/star/connection/XConnector.hpp>
#include <com/sun/star/frame/XDesktop.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
#include <cppuhelper/bootstrap.hxx>

namespace css = com::sun::star;
using css::uno::Reference;
using css::uno::Sequence;
using css::uno::UNO_QUERY_THROW;
#define STR rtl::OUString::createFromAscii

void test () {
    Reference<css::uno::XComponentContext> local_context (
            ::cppu::defaultBootstrap_InitialComponentContext());

    Reference<css::connection::XConnector> connector (
            local_context->getServiceManager()->createInstanceWithContext(
                    STR ("com.sun.star.connection.Connector"),
                    local_context),
            UNO_QUERY_THROW);

    Reference<css::connection::XConnection> connection (
            connector->connect (STR ("socket,host=127.0.0.1,port=8012")));

    Reference<css::bridge::XBridgeFactory> bridge_factory (
            local_context->getServiceManager()->createInstanceWithContext (
                    STR ("com.sun.star.bridge.BridgeFactory"),
                    local_context),
            UNO_QUERY_THROW);

    Reference<css::bridge::XBridge> bridge (
            bridge_factory->createBridge (STR (""), STR ("urp"), connection,
0));

    Reference<css::lang::XMultiComponentFactory> remote_service_manager (
            bridge->getInstance (STR ("StarOffice.ServiceManager")),
            UNO_QUERY_THROW);

    Reference<css::uno::XComponentContext> remote_context (
            Reference<css::beans::XPropertySet>::query
(remote_service_manager)
                ->getPropertyValue (STR ("DefaultContext")),
            UNO_QUERY_THROW);

    Reference<css::frame::XDesktop> desktop (
            remote_service_manager->createInstanceWithContext (
                    STR ("com.sun.star.frame.Desktop"),
                    remote_context),
            UNO_QUERY_THROW);

    desktop->terminate();
}

int main () {
    try {
        test();
        return 0;

    } catch (css::uno::Exception& e) {
        std::cerr << "Exception: "
                  << rtl::OUStringToOString (e.Message,
RTL_TEXTENCODING_UTF8).getStr()
                  << std::endl;
        return 1;
    }
}

Reply via email to