1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _COMPHELPER_COMPONENTFACTORY_HXX
25 #define _COMPHELPER_COMPONENTFACTORY_HXX
26 #include "comphelper/comphelperdllapi.h"
27 
28 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
29 
30 
31 /**
32  * @Descr
33  * Utilities to get an instance of a component if a ProcessServiceFactory
34  * is not available like it is the case in "small tools" as the Setup.
35  */
36 #include <com/sun/star/uno/Reference.h>
37 
38 
39 #ifdef UNX
40 // "libNAMExy.so" (__DLLEXTENSION == "xy.so")
41 #define LLCF_LIBNAME( name )	"lib" name __DLLEXTENSION
42 #else
43 // "NAMExy.dll" (__DLLEXTENSION == "xy")
44 #define LLCF_LIBNAME( name )	name __DLLEXTENSION ".dll"
45 #endif
46 
47 
48 namespace rtl {
49 	class OUString;
50 }
51 namespace com { namespace sun { namespace star {
52 	namespace uno {
53 		class XInterface;
54 	}
55 	namespace lang {
56 		class XSingleServiceFactory;
57 		class XMultiServiceFactory;
58 	}
59 	namespace registry {
60 		class XRegistryKey;
61 	}
62 }}}
63 
64 
65 namespace comphelper
66 {
67 
68 /**
69  * Get an instance of the component <code>rImplementationName</code> located
70  * in library <code>rLibraryName</code>. The instance must then be queried
71  * for the desired interface with a queryInterface call.
72  * The library name must be constructed with the macro
73  * <code>LLCF_LIBNAME( name )</code> if it is a library from the normal build
74  * process which includes build number and platform name.
75  *
76  * @example:C++
77  * <listing>
78 
79 	using namespace ::com::sun::star;
80 	using namespace ::com::sun::star::uno;
81 	Reference< whatever::XYourComponent > xComp;
82 	// library name, e.g. xyz603mi.dll or libxyz603.so
83 	::rtl::OUString aLibName( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( "xyz" ) ) );
84 	::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.whatever.YourComponent" ) );
85 	Reference< Xinterface > xI = ::comphelper::getComponentInstance( aLibName, aImplName );
86 	if ( xI.is() )
87 	{
88 		Any x = xI->queryInterface( ::getCppuType((const Reference< whatever::XYourComponent >*)0) );
89 		x >>= xComp;
90 	}
91 	if ( !xComp.is() )
92 		// you're lost
93 
94  * </listing>
95  */
96 COMPHELPER_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
97 	getComponentInstance(
98 		const ::rtl::OUString & rLibraryName,
99 		const ::rtl::OUString & rImplementationName
100 		);
101 
102 
103 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
104 	loadLibComponentFactory(
105 		const ::rtl::OUString & rLibraryName,
106 		const ::rtl::OUString & rImplementationName,
107 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF,
108 		const ::com::sun::star::uno::Reference< ::com::sun::star::registry::XRegistryKey > & xKey
109 		);
110 
111 
112 }	// namespace comphelper
113 
114 #endif // _COMPHELPER_COMPONENTFACTORY_HXX
115