diff options
Diffstat (limited to 'odk/examples/cpp/counter/countermain.cxx')
-rw-r--r-- | odk/examples/cpp/counter/countermain.cxx | 71 |
1 files changed, 25 insertions, 46 deletions
diff --git a/odk/examples/cpp/counter/countermain.cxx b/odk/examples/cpp/counter/countermain.cxx index 2a64acec106f..e1ab0a16eb76 100644 --- a/odk/examples/cpp/counter/countermain.cxx +++ b/odk/examples/cpp/counter/countermain.cxx @@ -69,57 +69,36 @@ using namespace ::rtl; //======================================================================= SAL_IMPLEMENT_MAIN() { - Reference< XSimpleRegistry > xReg = createSimpleRegistry(); - OSL_ENSURE( xReg.is(), "### cannot get service instance of \"com.sun.star.regiystry.SimpleRegistry\"!" ); - - xReg->open(OUString(RTL_CONSTASCII_USTRINGPARAM("counter.uno.rdb")), sal_False, sal_False); - OSL_ENSURE( xReg->isValid(), "### cannot open test registry \"counter.uno.rdb\"!" ); - - Reference< XComponentContext > xContext = bootstrap_InitialComponentContext(xReg); - OSL_ENSURE( xContext.is(), "### cannot creage intial component context!" ); - - Reference< XMultiComponentFactory > xMgr = xContext->getServiceManager(); - OSL_ENSURE( xMgr.is(), "### cannot get initial service manager!" ); - - // register my counter component - Reference< XImplementationRegistration > xImplReg( - xMgr->createInstanceWithContext(OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.ImplementationRegistration")), xContext), UNO_QUERY); - OSL_ENSURE( xImplReg.is(), "### cannot get service instance of \"com.sun.star.registry.ImplementationRegistration\"!" ); - - if (xImplReg.is()) - { - xImplReg->registerImplementation( - OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.loader.SharedLibrary")), // loader for component -#ifdef UNX -#ifdef MACOSX - OUString(RTL_CONSTASCII_USTRINGPARAM("counter.uno.dylib")), // component location -#else - OUString(RTL_CONSTASCII_USTRINGPARAM("counter.uno.so")), // component location -#endif -#else - OUString(RTL_CONSTASCII_USTRINGPARAM("counter.uno.dll")), // component location -#endif - Reference< XSimpleRegistry >() // registry omitted, - // defaulting to service manager registry used - ); - - // get a counter instance - Reference< XInterface > xx ; - xx = xMgr->createInstanceWithContext(OUString(RTL_CONSTASCII_USTRINGPARAM("foo.Counter")), xContext); + try { + + Reference< XComponentContext > xContext(::cppu::defaultBootstrap_InitialComponentContext()); + OSL_ENSURE( xContext.is(), "### bootstrap failed!\n" ); + + Reference< XMultiComponentFactory > xMgr = xContext->getServiceManager(); + OSL_ENSURE( xMgr.is(), "### cannot get initial service manager!" ); + + Reference< XInterface > xx = xMgr->createInstanceWithContext( + OUString::createFromAscii("foo.Counter"), xContext); + + OSL_ENSURE( xx.is(), "### cannot get service instance of \"foo.Counter\"!" ); + Reference< XCountable > xCount( xx, UNO_QUERY ); - OSL_ENSURE( xCount.is(), "### cannot get service instance of \"foo.Counter\"!" ); + OSL_ENSURE( xCount.is(), "### cannot query XCountable interface of service instance \"foo.Counter\"!" ); if (xCount.is()) { - xCount->setCount( 42 ); - fprintf( stdout , "%d," , xCount->getCount() ); - fprintf( stdout , "%d," , xCount->increment() ); - fprintf( stdout , "%d\n" , xCount->decrement() ); + xCount->setCount( 42 ); + fprintf( stdout , "%d," , (int)xCount->getCount() ); + fprintf( stdout , "%d," , (int)xCount->increment() ); + fprintf( stdout , "%d\n" , (int)xCount->decrement() ); } - } - Reference< XComponent >::query( xContext )->dispose(); - return 0; -} + Reference< XComponent >::query( xContext )->dispose(); + + } catch( Exception& e) { + printf("Error: caught exception:\n %s\n", + OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr()); + exit(1); + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |