xref: /AOO41X/main/cli_ure/source/native/native_bootstrap.cxx (revision ff3f4ebcaa9d89f80fc1bbfab0aded7b897d9f72)
154c06456SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
354c06456SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
454c06456SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
554c06456SAndrew Rist  * distributed with this work for additional information
654c06456SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
754c06456SAndrew Rist  * to you under the Apache License, Version 2.0 (the
854c06456SAndrew Rist  * "License"); you may not use this file except in compliance
954c06456SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1154c06456SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1354c06456SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1454c06456SAndrew Rist  * software distributed under the License is distributed on an
1554c06456SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1654c06456SAndrew Rist  * KIND, either express or implied.  See the License for the
1754c06456SAndrew Rist  * specific language governing permissions and limitations
1854c06456SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2054c06456SAndrew Rist  *************************************************************/
2154c06456SAndrew Rist 
2254c06456SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // Use UNICODE Windows and C API.
25cdf0e10cSrcweir #define _UNICODE
26cdf0e10cSrcweir #define UNICODE
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #ifdef _MSC_VER
29cdf0e10cSrcweir #pragma warning(push, 1)
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <windows.h>
32cdf0e10cSrcweir #include "uno/environment.hxx"
33cdf0e10cSrcweir #ifdef _MSC_VER
34cdf0e10cSrcweir #pragma warning(pop)
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <tchar.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "native_share.h"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
42cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
43cdf0e10cSrcweir #include "cppuhelper/bootstrap.hxx"
44cdf0e10cSrcweir #include <delayimp.h>
45cdf0e10cSrcweir #include <stdio.h>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using namespace ::rtl;
48cdf0e10cSrcweir using namespace ::com::sun::star;
49cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace cli_ure {
52cdf0e10cSrcweir     WCHAR * resolveLink(WCHAR * path);
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55*ff3f4ebcSOliver-Rainer Wittmann // INSTALL_PATH value needs to correspond to the Windows registry subkey
56*ff3f4ebcSOliver-Rainer Wittmann // in main\scp2\source\ooo\registryitem_ooo.scp
57*ff3f4ebcSOliver-Rainer Wittmann #define INSTALL_PATH L"Software\\Apache OpenOffice\\UNO\\InstallPath"
58cdf0e10cSrcweir #define BASIS_LINK L"\\basis-link"
59cdf0e10cSrcweir #define URE_LINK L"\\ure-link"
60cdf0e10cSrcweir #define URE_BIN L"\\bin"
61cdf0e10cSrcweir #define UNO_PATH L"UNO_PATH"
62cdf0e10cSrcweir 
63cdf0e10cSrcweir namespace
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 
66cdf0e10cSrcweir  /*
67cdf0e10cSrcweir  * Gets the installation path from the Windows Registry for the specified
68cdf0e10cSrcweir  * registry key.
69cdf0e10cSrcweir  *
70cdf0e10cSrcweir  * @param hroot       open handle to predefined root registry key
71cdf0e10cSrcweir  * @param subKeyName  name of the subkey to open
72cdf0e10cSrcweir  *
73cdf0e10cSrcweir  * @return the installation path or NULL, if no installation was found or
74cdf0e10cSrcweir  *         if an error occured
75cdf0e10cSrcweir  */
76cdf0e10cSrcweir WCHAR* getPathFromRegistryKey( HKEY hroot, LPCWSTR subKeyName )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     HKEY hkey;
79cdf0e10cSrcweir     DWORD type;
80cdf0e10cSrcweir     TCHAR* data = NULL;
81cdf0e10cSrcweir     DWORD size;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     /* open the specified registry key */
84cdf0e10cSrcweir     if ( RegOpenKeyEx( hroot, subKeyName, 0, KEY_READ, &hkey ) != ERROR_SUCCESS )
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         return NULL;
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     /* find the type and size of the default value */
90cdf0e10cSrcweir     if ( RegQueryValueEx( hkey, NULL, NULL, &type, NULL, &size) != ERROR_SUCCESS )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         RegCloseKey( hkey );
93cdf0e10cSrcweir         return NULL;
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /* get memory to hold the default value */
97cdf0e10cSrcweir     data = new WCHAR[size];
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /* read the default value */
100cdf0e10cSrcweir     if ( RegQueryValueEx( hkey, NULL, NULL, &type, (LPBYTE) data, &size ) != ERROR_SUCCESS )
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         RegCloseKey( hkey );
103cdf0e10cSrcweir         return NULL;
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     /* release registry key handle */
107cdf0e10cSrcweir     RegCloseKey( hkey );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     return data;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir /* If the path does not end with '\' the las segment will be removed.
113cdf0e10cSrcweir     path: C:\a\b
114cdf0e10cSrcweir     ->    C:\a
115cdf0e10cSrcweir     @param io_path
116cdf0e10cSrcweir         in/out parameter. The string is not reallocated. Simply a '\0'
117cdf0e10cSrcweir         will be inserted to shorten the string.
118cdf0e10cSrcweir */
119cdf0e10cSrcweir void oneDirUp(LPTSTR io_path)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     WCHAR * pEnd = io_path + lstrlen(io_path) - 1;
122cdf0e10cSrcweir     while (pEnd > io_path //prevent crashing if provided string does not contain a backslash
123cdf0e10cSrcweir         && *pEnd != L'\\')
124cdf0e10cSrcweir         pEnd --;
125cdf0e10cSrcweir     *pEnd = L'\0';
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir /* Returns the path to the program folder of the brand layer,
130cdf0e10cSrcweir     for example c:/openoffice.org 3/program
131cdf0e10cSrcweir    This path is either obtained from the environment variable UNO_PATH
132cdf0e10cSrcweir    or the registry item
133*ff3f4ebcSOliver-Rainer Wittmann    "Software\\Apache OpenOffice\\UNO\\InstallPath"
134cdf0e10cSrcweir    either in HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE
135cdf0e10cSrcweir    The return value must be freed with delete[]
136cdf0e10cSrcweir */
137cdf0e10cSrcweir WCHAR * getInstallPath()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     WCHAR * szInstallPath = NULL;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     DWORD  cChars = GetEnvironmentVariable(UNO_PATH, NULL, 0);
142cdf0e10cSrcweir     if (cChars > 0)
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         szInstallPath = new WCHAR[cChars];
145cdf0e10cSrcweir         cChars = GetEnvironmentVariable(UNO_PATH, szInstallPath, cChars);
146cdf0e10cSrcweir 		//If PATH is not set then it is no error
147cdf0e10cSrcweir 		if (cChars == 0)
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			delete[] szInstallPath;
150cdf0e10cSrcweir 			return NULL;
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     if (! szInstallPath)
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         szInstallPath = getPathFromRegistryKey( HKEY_CURRENT_USER, INSTALL_PATH );
157cdf0e10cSrcweir         if ( szInstallPath == NULL )
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             /* read the key's default value from HKEY_LOCAL_MACHINE */
160cdf0e10cSrcweir             szInstallPath = getPathFromRegistryKey( HKEY_LOCAL_MACHINE, INSTALL_PATH );
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir     return szInstallPath;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir /* Returns the path to the URE/bin path, where cppuhelper lib resides.
167cdf0e10cSrcweir     The returned string must be freed with delete[]
168cdf0e10cSrcweir */
169cdf0e10cSrcweir WCHAR* getUnoPath()
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     WCHAR * szLinkPath = NULL;
172cdf0e10cSrcweir     WCHAR * szUrePath = NULL;
173cdf0e10cSrcweir     WCHAR * szUreBin = NULL; //the return value
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     WCHAR * szInstallPath = getInstallPath();
176cdf0e10cSrcweir     if (szInstallPath)
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir         //build the path tho the basis-link file
179cdf0e10cSrcweir         oneDirUp(szInstallPath);
180cdf0e10cSrcweir         int sizeLinkPath = lstrlen(szInstallPath) + lstrlen(INSTALL_PATH) + 1;
181cdf0e10cSrcweir         if (sizeLinkPath < MAX_PATH)
182cdf0e10cSrcweir             sizeLinkPath = MAX_PATH;
183cdf0e10cSrcweir         szLinkPath = new WCHAR[sizeLinkPath];
184cdf0e10cSrcweir         szLinkPath[0] = L'\0';
185cdf0e10cSrcweir         lstrcat(szLinkPath, szInstallPath);
186cdf0e10cSrcweir         lstrcat(szLinkPath, BASIS_LINK);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         //get the path to the actual Basis folder
189cdf0e10cSrcweir         if (cli_ure::resolveLink(szLinkPath))
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             //build the path to the ure-link file
192cdf0e10cSrcweir             int sizeUrePath = lstrlen(szLinkPath) + lstrlen(URE_LINK) + 1;
193cdf0e10cSrcweir             if (sizeUrePath < MAX_PATH)
194cdf0e10cSrcweir                 sizeUrePath = MAX_PATH;
195cdf0e10cSrcweir             szUrePath = new WCHAR[sizeUrePath];
196cdf0e10cSrcweir             szUrePath[0] = L'\0';
197cdf0e10cSrcweir             lstrcat(szUrePath, szLinkPath);
198cdf0e10cSrcweir             lstrcat(szUrePath, URE_LINK);
199cdf0e10cSrcweir 
200cdf0e10cSrcweir             //get the path to the actual Ure folder
201cdf0e10cSrcweir             if (cli_ure::resolveLink(szUrePath))
202cdf0e10cSrcweir             {
203cdf0e10cSrcweir                 //build the path to the URE/bin directory
204cdf0e10cSrcweir         	    szUreBin = new WCHAR[lstrlen(szUrePath) + lstrlen(URE_BIN) + 1];
205cdf0e10cSrcweir  	            szUreBin[0] = L'\0';
206cdf0e10cSrcweir                 lstrcat(szUreBin, szUrePath);
207cdf0e10cSrcweir  	            lstrcat(szUreBin, URE_BIN);
208cdf0e10cSrcweir             }
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir #if OSL_DEBUG_LEVEL >=2
212cdf0e10cSrcweir     if (szUreBin)
213cdf0e10cSrcweir     {
214cdf0e10cSrcweir         fwprintf(stdout,L"[cli_cppuhelper]: Path to URE libraries:\n %s \n", szUreBin);
215cdf0e10cSrcweir     }
216cdf0e10cSrcweir     else
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         fwprintf(stdout,L"[cli_cppuhelper]: Failed to determine location of URE.\n");
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir #endif
221cdf0e10cSrcweir     delete[] szInstallPath;
222cdf0e10cSrcweir     delete[] szLinkPath;
223cdf0e10cSrcweir     delete[] szUrePath;
224cdf0e10cSrcweir     return szUreBin;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 
228cdf0e10cSrcweir /*We extend the path to contain the Ure/bin folder,
229cdf0e10cSrcweir   so that components can use osl_loadModule with arguments, such as
230cdf0e10cSrcweir   "reg3.dll". That is, the arguments are only the library names.
231cdf0e10cSrcweir */
232cdf0e10cSrcweir void extendPath(LPCWSTR szUreBinPath)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir 	if (!szUreBinPath)
235cdf0e10cSrcweir 		return;
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     WCHAR * sEnvPath = NULL;
238cdf0e10cSrcweir     DWORD  cChars = GetEnvironmentVariable(L"PATH", sEnvPath, 0);
239cdf0e10cSrcweir     if (cChars > 0)
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         sEnvPath = new WCHAR[cChars];
242cdf0e10cSrcweir         cChars = GetEnvironmentVariable(L"PATH", sEnvPath, cChars);
243cdf0e10cSrcweir 		//If PATH is not set then it is no error
244cdf0e10cSrcweir 		if (cChars == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND)
245cdf0e10cSrcweir 		{
246cdf0e10cSrcweir 			delete[] sEnvPath;
247cdf0e10cSrcweir 			return;
248cdf0e10cSrcweir 		}
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir     //prepare the new PATH. Add the Ure/bin directory at the front.
251cdf0e10cSrcweir     //note also adding ';'
252cdf0e10cSrcweir     WCHAR * sNewPath = new WCHAR[lstrlen(sEnvPath) + lstrlen(szUreBinPath) + 2];
253cdf0e10cSrcweir     sNewPath[0] = L'\0';
254cdf0e10cSrcweir 	lstrcat(sNewPath, szUreBinPath);
255cdf0e10cSrcweir 	if (lstrlen(sEnvPath))
256cdf0e10cSrcweir 	{
257cdf0e10cSrcweir 		lstrcat(sNewPath, L";");
258cdf0e10cSrcweir 		lstrcat(sNewPath, sEnvPath);
259cdf0e10cSrcweir 	}
260cdf0e10cSrcweir     BOOL bSet = SetEnvironmentVariable(L"PATH", sNewPath);
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     delete[] sEnvPath;
263cdf0e10cSrcweir     delete[] sNewPath;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir HMODULE loadFromPath(LPCWSTR sLibName)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	if (sLibName == NULL)
270cdf0e10cSrcweir 		return NULL;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	WCHAR * szUreBinPath =  getUnoPath();
273cdf0e10cSrcweir 	if (!szUreBinPath)
274cdf0e10cSrcweir 		return NULL;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     extendPath(szUreBinPath);
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     WCHAR*  szFullPath = new WCHAR[lstrlen(sLibName) + lstrlen(szUreBinPath) + 2];
279cdf0e10cSrcweir     szFullPath[0] = L'\0';
280cdf0e10cSrcweir     lstrcat(szFullPath, szUreBinPath);
281cdf0e10cSrcweir     lstrcat(szFullPath, L"\\");
282cdf0e10cSrcweir     lstrcat(szFullPath, sLibName);
283cdf0e10cSrcweir     HMODULE handle = LoadLibraryEx(szFullPath, NULL,
284cdf0e10cSrcweir 		LOAD_WITH_ALTERED_SEARCH_PATH);
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     delete[] szFullPath;
287cdf0e10cSrcweir     delete[] szUreBinPath;
288cdf0e10cSrcweir 	return handle;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir /*Hook for delayed loading of libraries which this library is linked with.
292cdf0e10cSrcweir     This is a failure hook. That is, it is only called when the loading of
293cdf0e10cSrcweir     a library failed. It will be called when loading of cppuhelper failed.
294cdf0e10cSrcweir     Because we extend the PATH to the URE/bin folder while this function is
295cdf0e10cSrcweir     executed (see extendPath), all other libraries are found.
296cdf0e10cSrcweir */
297cdf0e10cSrcweir extern "C" FARPROC WINAPI delayLoadHook(
298cdf0e10cSrcweir     unsigned        dliNotify,
299cdf0e10cSrcweir     PDelayLoadInfo  pdli
300cdf0e10cSrcweir     )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir     if (dliNotify == dliFailLoadLib)
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         LPWSTR szLibName = NULL;
305cdf0e10cSrcweir      	//Convert the ansi file name to wchar_t*
306cdf0e10cSrcweir 		int size = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pdli->szDll, -1, NULL, 0);
307cdf0e10cSrcweir 		if (size > 0)
308cdf0e10cSrcweir 		{
309cdf0e10cSrcweir 			szLibName = new WCHAR[size];
310cdf0e10cSrcweir 			if (! MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pdli->szDll, -1, szLibName, size))
311cdf0e10cSrcweir 			{
312cdf0e10cSrcweir                 return 0;
313cdf0e10cSrcweir 			}
314cdf0e10cSrcweir 		}
315cdf0e10cSrcweir         HANDLE h = loadFromPath(szLibName);
316cdf0e10cSrcweir         delete[] szLibName;
317cdf0e10cSrcweir 		return (FARPROC) h;
318cdf0e10cSrcweir     }
319cdf0e10cSrcweir     return 0;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir ExternC
324cdf0e10cSrcweir PfnDliHook   __pfnDliFailureHook2 = delayLoadHook;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir namespace uno
327cdf0e10cSrcweir {
328cdf0e10cSrcweir namespace util
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 
331cdf0e10cSrcweir /** Bootstrapping native UNO.
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     Bootstrapping requires the existence of many libraries which are contained
334cdf0e10cSrcweir     in an URE installation. To find and load these libraries the Windows
335*ff3f4ebcSOliver-Rainer Wittmann     registry keys HKEY_CURRENT_USER\Software\Apache OpenOffice\Layer\URE\1
336*ff3f4ebcSOliver-Rainer Wittmann     and HKEY_LOCAL_MACHINE\Software\Apache OpenOffice\Layer\URE\1 are examined.
337cdf0e10cSrcweir     These contain a named value UREINSTALLLOCATION which holds a path to the URE
338cdf0e10cSrcweir 	installation folder.
339cdf0e10cSrcweir */
340cdf0e10cSrcweir public __sealed __gc class Bootstrap
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     inline Bootstrap() {}
343cdf0e10cSrcweir 
344cdf0e10cSrcweir public:
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     /** Bootstraps the initial component context from a native UNO installation.
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         @see cppuhelper/bootstrap.hxx:defaultBootstrap_InitialComponentContext()
349cdf0e10cSrcweir     */
350cdf0e10cSrcweir     static ::unoidl::com::sun::star::uno::XComponentContext *
351cdf0e10cSrcweir         defaultBootstrap_InitialComponentContext();
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     /** Bootstraps the initial component context from a native UNO installation.
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         @param ini_file
356cdf0e10cSrcweir                a file URL of an ini file, e.g. uno.ini/unorc. (The ini file must
357cdf0e10cSrcweir                reside next to the cppuhelper library)
358cdf0e10cSrcweir         @param bootstrap_parameters
359cdf0e10cSrcweir                bootstrap parameters (maybe null)
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         @see cppuhelper/bootstrap.hxx:defaultBootstrap_InitialComponentContext()
362cdf0e10cSrcweir     */
363cdf0e10cSrcweir     static ::unoidl::com::sun::star::uno::XComponentContext *
364cdf0e10cSrcweir         defaultBootstrap_InitialComponentContext(
365cdf0e10cSrcweir             ::System::String * ini_file,
366cdf0e10cSrcweir             ::System::Collections::IDictionaryEnumerator *
367cdf0e10cSrcweir               bootstrap_parameters );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     /** Bootstraps the initial component context from a native UNO installation.
370cdf0e10cSrcweir 
371cdf0e10cSrcweir     @see cppuhelper/bootstrap.hxx:bootstrap()
372cdf0e10cSrcweir      */
373cdf0e10cSrcweir     static ::unoidl::com::sun::star::uno::XComponentContext *
374cdf0e10cSrcweir     bootstrap();
375cdf0e10cSrcweir };
376cdf0e10cSrcweir 
377cdf0e10cSrcweir //______________________________________________________________________________
378cdf0e10cSrcweir ::unoidl::com::sun::star::uno::XComponentContext *
379cdf0e10cSrcweir Bootstrap::defaultBootstrap_InitialComponentContext(
380cdf0e10cSrcweir     ::System::String * ini_file,
381cdf0e10cSrcweir     ::System::Collections::IDictionaryEnumerator * bootstrap_parameters )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     if (0 != bootstrap_parameters)
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         bootstrap_parameters->Reset();
386cdf0e10cSrcweir         while (bootstrap_parameters->MoveNext())
387cdf0e10cSrcweir         {
388cdf0e10cSrcweir             OUString key(
389cdf0e10cSrcweir                 String_to_ustring( __try_cast< ::System::String * >(
390cdf0e10cSrcweir                                        bootstrap_parameters->get_Key() ) ) );
391cdf0e10cSrcweir             OUString value(
392cdf0e10cSrcweir                 String_to_ustring( __try_cast< ::System::String * >(
393cdf0e10cSrcweir                                        bootstrap_parameters->get_Value() ) ) );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir             ::rtl::Bootstrap::set( key, value );
396cdf0e10cSrcweir         }
397cdf0e10cSrcweir     }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     // bootstrap native uno
400cdf0e10cSrcweir     Reference< XComponentContext > xContext;
401cdf0e10cSrcweir     if (0 == ini_file)
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir         xContext = ::cppu::defaultBootstrap_InitialComponentContext();
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir     else
406cdf0e10cSrcweir     {
407cdf0e10cSrcweir         xContext = ::cppu::defaultBootstrap_InitialComponentContext(
408cdf0e10cSrcweir             String_to_ustring( __try_cast< ::System::String * >( ini_file ) ) );
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     return __try_cast< ::unoidl::com::sun::star::uno::XComponentContext * >(
412cdf0e10cSrcweir         to_cli( xContext ) );
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir //______________________________________________________________________________
416cdf0e10cSrcweir ::unoidl::com::sun::star::uno::XComponentContext *
417cdf0e10cSrcweir Bootstrap::defaultBootstrap_InitialComponentContext()
418cdf0e10cSrcweir {
419cdf0e10cSrcweir     return defaultBootstrap_InitialComponentContext( 0, 0 );
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir ::unoidl::com::sun::star::uno::XComponentContext * Bootstrap::bootstrap()
423cdf0e10cSrcweir {
424cdf0e10cSrcweir     Reference<XComponentContext> xContext = ::cppu::bootstrap();
425cdf0e10cSrcweir     return __try_cast< ::unoidl::com::sun::star::uno::XComponentContext * >(
426cdf0e10cSrcweir         to_cli( xContext ) );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir }
431cdf0e10cSrcweir }
432