summaryrefslogtreecommitdiff
path: root/cli_ure
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2004-07-12 12:05:55 +0000
committerRüdiger Timm <rt@openoffice.org>2004-07-12 12:05:55 +0000
commit93c6a79800dc82c5c1699a87d29363df9cddf09e (patch)
treea544005499b67aa05b8827db563ed4c543b453f4 /cli_ure
parent664480ec042d8417a6193f7b66047828901c3a70 (diff)
INTEGRATION: CWS jl9 (1.4.24); FILE MERGED
2004/07/01 11:30:07 jl 1.4.24.4: #i29787# added bootstrap() 2004/07/01 08:27:46 jl 1.4.24.3: #i29787# 2004/06/21 15:03:48 jl 1.4.24.2: #i20317# strongly named assemblies 2004/06/02 14:45:53 jl 1.4.24.1: #i29787# cli_cppuhelper uses delayload for its linked libraries
Diffstat (limited to 'cli_ure')
-rw-r--r--cli_ure/source/native/native_bootstrap.cxx147
1 files changed, 138 insertions, 9 deletions
diff --git a/cli_ure/source/native/native_bootstrap.cxx b/cli_ure/source/native/native_bootstrap.cxx
index b46c5e7a826f..42882c17569a 100644
--- a/cli_ure/source/native/native_bootstrap.cxx
+++ b/cli_ure/source/native/native_bootstrap.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: native_bootstrap.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: dbo $ $Date: 2003-08-20 12:53:21 $
+ * last change: $Author: rt $ $Date: 2004-07-12 13:05:55 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -63,23 +63,136 @@
#include "rtl/bootstrap.hxx"
#include "cppuhelper/bootstrap.hxx"
-
-
-[assembly:System::Reflection::AssemblyProduct( "CLI-UNO Language Binding" )];
-// xxx todo AssemblyCompany, AssemblyCopyright, AssemblyTrademark
-[assembly:System::Reflection::AssemblyDescription( "CLI-UNO Helper Library" )];
-[assembly:System::Reflection::AssemblyVersion( "3.1.0.0" )];
+#include <windows.h>
+#include <delayimp.h>
+#include <stdio.h>
using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
+#define OFFICE_LOCATION_REGISTRY_KEY "Software\\OpenOffice.org\\UNO\\InstallPath"
+
+
+#pragma unmanaged
+
+namespace
+{
+char* getLibraryPath()
+{
+ static char* sPath;
+ //do not use oslMutex here. That would cause to load sal and we would
+ //run in a loop with delayLoadHook
+ if (sPath == NULL)
+ {
+ bool failed = false;
+ HKEY hKey = 0;
+ if (RegOpenKeyExA(HKEY_CURRENT_USER,OFFICE_LOCATION_REGISTRY_KEY,
+ 0, KEY_READ, &hKey) != ERROR_SUCCESS)
+ {
+ if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, OFFICE_LOCATION_REGISTRY_KEY,
+ 0, KEY_READ, &hKey) != ERROR_SUCCESS)
+ {
+ OSL_ASSERT(0);
+ fprintf(stderr, "cli_cppuhelper: Office not properly installed. "
+ "Could not open registry keys.");
+ failed = true;
+ }
+ }
+ if (failed)
+ return NULL;
+
+ DWORD dwType = 0;
+ DWORD dwLen = 0;
+ char *arData = NULL;
+ //get the length for the path to office
+ if (RegQueryValueExA(hKey, NULL, NULL, &dwType, NULL,
+ &dwLen) == ERROR_SUCCESS)
+ {
+ arData = new char[dwLen];
+ if (RegQueryValueExA(hKey, NULL, NULL, &dwType, (LPBYTE) arData,
+ & dwLen) == ERROR_SUCCESS)
+ {
+ sPath = strdup(arData);
+#if OSL_DEBUG_LEVEL >=2
+ fprintf(stdout,"[cli_cppuhelper]: Using path %s to load office libraries.", sPath);
+#endif
+ }
+ delete [] arData;
+ }
+ RegCloseKey(hKey);
+
+ //We extend the path to contain the program directory of the office,
+ //so that components can use osl_loadModule with arguments, such as
+ //"reg3.dll". That is, the arguments are only the library names.
+ char * sEnvPath = getenv("PATH");
+ char * buff = NULL;
+ if (sEnvPath)
+ buff = new char[sizeof("PATH=") + strlen(sEnvPath) + strlen(sPath) + 2];
+ else
+ buff = new char[sizeof("PATH=") + strlen(sPath) + 2];
+ buff[0] = 0;
+ strcat(buff, "PATH=");
+ strcat(buff, sPath);
+ if (sEnvPath)
+ {
+ strcat(buff, ";");
+ strcat(buff, sEnvPath);
+ }
+ putenv(buff);
+ }
+
+ return sPath;
+}
+
+
+//Hook for delayed loading of libraries which this library is linked with.
+extern "C" FARPROC WINAPI delayLoadHook(
+ unsigned dliNotify,
+ PDelayLoadInfo pdli
+ )
+{
+ if (dliNotify == dliFailLoadLib)
+ {
+ char* sPath = getLibraryPath();
+ int lenPath = strlen(sPath);
+ //create string to contain the full path to cppuhelper
+ int lenLib = strlen(pdli->szDll);
+ char* sFullPath = new char[lenLib + lenPath + 2];
+ sFullPath[0] = 0;
+ sFullPath = strcat(sFullPath, sPath);
+ sFullPath = strcat(sFullPath, "\\");
+ sFullPath = strcat(sFullPath, pdli->szDll);
+
+ HMODULE handle = LoadLibraryExA(sFullPath, NULL,
+ LOAD_WITH_ALTERED_SEARCH_PATH);
+ delete[] sFullPath;
+ return (FARPROC) handle;
+ }
+ return 0;
+}
+}
+
+ExternC
+PfnDliHook __pfnDliFailureHook2 = delayLoadHook;
+#pragma managed
+
namespace uno
{
namespace util
{
/** Bootstrapping native UNO.
+
+ Bootstrapping requires the existence of many libraries which are contained
+ in an office installation. To find and load these libraries the Windows
+ registry keys HKEY_CURRENT_USER\Software\OpenOffice.org\UNO\InstallPath
+ and HKEY_LOCAL_MACHINE\Software\OpenOffice.org\UNO\InstallPath are examined.
+ These contain the paths to the program folder of the office which was
+ installed most recently. Please note that the office's setup either
+ writes the key in HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE dependent on
+ whether the user chooses a user installation or an installation for all
+ users.
*/
public __sealed __gc class Bootstrap
{
@@ -97,7 +210,8 @@ public:
/** Bootstraps the initial component context from a native UNO installation.
@param ini_file
- ini_file (may be null: uno.ini/unorc besides cppuhelper lib)
+ a file URL of an ini file, e.g. uno.ini/unorc. (The ini file must
+ reside next to the cppuhelper library)
@param bootstrap_parameters
bootstrap parameters (maybe null)
@@ -108,6 +222,13 @@ public:
::System::String * ini_file,
::System::Collections::IDictionaryEnumerator *
bootstrap_parameters );
+
+ /** Bootstraps the initial component context from a native UNO installation.
+
+ @see cppuhelper/bootstrap.hxx:bootstrap()
+ */
+ static ::unoidl::com::sun::star::uno::XComponentContext *
+ bootstrap();
};
//______________________________________________________________________________
@@ -155,5 +276,13 @@ Bootstrap::defaultBootstrap_InitialComponentContext()
return defaultBootstrap_InitialComponentContext( 0, 0 );
}
+::unoidl::com::sun::star::uno::XComponentContext * Bootstrap::bootstrap()
+{
+ Reference<XComponentContext> xContext = ::cppu::bootstrap();
+ return __try_cast< ::unoidl::com::sun::star::uno::XComponentContext * >(
+ to_cli( xContext ) );
+
+}
+
}
}