1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _COMPHELPER_COMPONENTFACTORY_HXX 29 #define _COMPHELPER_COMPONENTFACTORY_HXX 30 #include "comphelper/comphelperdllapi.h" 31 32 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 33 34 35 /** 36 * @Descr 37 * Utilities to get an instance of a component if a ProcessServiceFactory 38 * is not available like it is the case in "small tools" as the Setup. 39 */ 40 #include <com/sun/star/uno/Reference.h> 41 42 43 #ifdef UNX 44 // "libNAMExy.so" (__DLLEXTENSION == "xy.so") 45 #define LLCF_LIBNAME( name ) "lib" name __DLLEXTENSION 46 #else 47 // "NAMExy.dll" (__DLLEXTENSION == "xy") 48 #define LLCF_LIBNAME( name ) name __DLLEXTENSION ".dll" 49 #endif 50 51 52 namespace rtl { 53 class OUString; 54 } 55 namespace com { namespace sun { namespace star { 56 namespace uno { 57 class XInterface; 58 } 59 namespace lang { 60 class XSingleServiceFactory; 61 class XMultiServiceFactory; 62 } 63 namespace registry { 64 class XRegistryKey; 65 } 66 }}} 67 68 69 namespace comphelper 70 { 71 72 /** 73 * Get an instance of the component <code>rImplementationName</code> located 74 * in library <code>rLibraryName</code>. The instance must then be queried 75 * for the desired interface with a queryInterface call. 76 * The library name must be constructed with the macro 77 * <code>LLCF_LIBNAME( name )</code> if it is a library from the normal build 78 * process which includes build number and platform name. 79 * 80 * @example:C++ 81 * <listing> 82 83 using namespace ::com::sun::star; 84 using namespace ::com::sun::star::uno; 85 Reference< whatever::XYourComponent > xComp; 86 // library name, e.g. xyz603mi.dll or libxyz603.so 87 ::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( "xyz" ) ) ); 88 ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.whatever.YourComponent" ) ); 89 Reference< Xinterface > xI = ::comphelper::getComponentInstance( aLibName, aImplName ); 90 if ( xI.is() ) 91 { 92 Any x = xI->queryInterface( ::getCppuType((const Reference< whatever::XYourComponent >*)0) ); 93 x >>= xComp; 94 } 95 if ( !xComp.is() ) 96 // you're lost 97 98 * </listing> 99 */ 100 COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > 101 getComponentInstance( 102 const ::rtl::OUString & rLibraryName, 103 const ::rtl::OUString & rImplementationName 104 ); 105 106 107 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > 108 loadLibComponentFactory( 109 const ::rtl::OUString & rLibraryName, 110 const ::rtl::OUString & rImplementationName, 111 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, 112 const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > & xKey 113 ); 114 115 116 } // namespace comphelper 117 118 #endif // _COMPHELPER_COMPONENTFACTORY_HXX 119