22#include "rtl/bootstrap.hxx"
23#include "com/sun/star/uno/XComponentContext.hpp"
27#define WIN32_LEAN_AND_MEAN
31#define INSTALL_PATH L"Software\\LibreOffice\\UNO\\InstallPath"
32#define UNO_PATH L"UNO_PATH"
45WCHAR* getPathFromRegistryKey( HKEY hroot, LPCWSTR subKeyName )
49 if ( RegOpenKeyExW( hroot, subKeyName, 0, KEY_READ, &hkey ) != ERROR_SUCCESS )
52 struct CloseKeyGuard {
54 ~CloseKeyGuard() { RegCloseKey( m_hkey ); }
55 } aCloseKeyGuard{hkey};
60 if ( RegQueryValueExW( hkey,
nullptr,
nullptr, &
type,
nullptr, &
size ) != ERROR_SUCCESS )
64 std::unique_ptr<WCHAR[]> data(
new WCHAR[
size]);
67 if ( RegQueryValueExW( hkey,
nullptr,
nullptr, &
type,
reinterpret_cast<LPBYTE
>(data.get()), &
size ) != ERROR_SUCCESS )
70 return data.release();
80WCHAR* getInstallPath()
82 std::unique_ptr<WCHAR[]> szInstallPath;
84 DWORD cChars = GetEnvironmentVariableW(
UNO_PATH,
nullptr, 0);
87 szInstallPath.reset(
new WCHAR[cChars]);
88 cChars = GetEnvironmentVariableW(
UNO_PATH, szInstallPath.get(), cChars);
96 szInstallPath.reset(getPathFromRegistryKey( HKEY_CURRENT_USER,
INSTALL_PATH ));
100 szInstallPath.reset(getPathFromRegistryKey( HKEY_LOCAL_MACHINE,
INSTALL_PATH ));
103 return szInstallPath.release();
110void extendPath(LPCWSTR szPath)
115 std::unique_ptr<WCHAR[]> sEnvPath;
116 DWORD cChars = GetEnvironmentVariableW(L
"PATH",
nullptr, 0);
119 sEnvPath.reset(
new WCHAR[cChars]);
120 cChars = GetEnvironmentVariableW(L
"PATH", sEnvPath.get(), cChars);
122 if (cChars == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND)
127 std::unique_ptr<WCHAR[]> sNewPath(
new WCHAR[lstrlenW(sEnvPath.get()) + lstrlenW(szPath) + 2]);
128 lstrcpyW(sNewPath.get(), szPath);
129 if (lstrlenW(sEnvPath.get()))
131 lstrcatW(sNewPath.get(), L
";");
132 lstrcatW(sNewPath.get(), sEnvPath.get());
134 SetEnvironmentVariableW(L
"PATH", sNewPath.get());
137HMODULE loadFromPath(LPCSTR sLibName)
143 int size = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sLibName, -1,
nullptr, 0);
146 std::unique_ptr<WCHAR[]> wsLibName(
new WCHAR[
size]);
147 if (!MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sLibName, -1, wsLibName.get(),
size))
150 std::unique_ptr<WCHAR[]> szPath(getInstallPath());
154 extendPath(szPath.get());
156 std::unique_ptr<WCHAR[]> szFullPath(
new WCHAR[lstrlenW(wsLibName.get()) + lstrlenW(szPath.get()) + 2]);
157 lstrcpyW(szFullPath.get(), szPath.get());
158 lstrcatW(szFullPath.get(), L
"\\");
159 lstrcatW(szFullPath.get(), wsLibName.get());
160 HMODULE handle = LoadLibraryW(szFullPath.get());
170extern "C" FARPROC WINAPI delayLoadHook(
171 unsigned int dliNotify,
175 if (dliNotify == dliFailLoadLib)
177 HANDLE
h = loadFromPath(pdli->szDll);
178 return reinterpret_cast<FARPROC
>(
h);
214 static ::unoidl::com::sun::star::uno::XComponentContext ^
227 static ::unoidl::com::sun::star::uno::XComponentContext ^
229 ::System::String ^ ini_file,
230 ::System::Collections::IDictionaryEnumerator ^
231 bootstrap_parameters );
237 static ::unoidl::com::sun::star::uno::XComponentContext ^
242::unoidl::com::sun::star::uno::XComponentContext ^
243Bootstrap::defaultBootstrap_InitialComponentContext(
244 ::System::String ^ ini_file,
245 ::System::Collections::IDictionaryEnumerator ^ bootstrap_parameters )
247 if (
nullptr != bootstrap_parameters)
249 bootstrap_parameters->Reset();
250 while (bootstrap_parameters->MoveNext())
254 bootstrap_parameters->Key ) ) );
257 bootstrap_parameters->Value ) ) );
259 ::rtl::Bootstrap::set( key, value );
264 Reference< XComponentContext > xContext;
265 if (
nullptr == ini_file)
267 xContext = ::cppu::defaultBootstrap_InitialComponentContext();
271 xContext = ::cppu::defaultBootstrap_InitialComponentContext(
275 return safe_cast< ::unoidl::com::sun::star::uno::XComponentContext ^ >(
280::unoidl::com::sun::star::uno::XComponentContext ^
281Bootstrap::defaultBootstrap_InitialComponentContext()
286::unoidl::com::sun::star::uno::XComponentContext ^ Bootstrap::bootstrap()
288 Reference<XComponentContext> xContext = ::cppu::bootstrap();
289 return safe_cast< ::unoidl::com::sun::star::uno::XComponentContext ^ >(
::unoidl::com::sun::star::uno::XComponentContext defaultBootstrap_InitialComponentContext(::System::String ^ ini_file, ::System::Collections::IDictionaryEnumerator ^ bootstrap_parameters)
Bootstraps the initial component context from a native UNO installation.
::unoidl::com::sun::star::uno::XComponentContext bootstrap()
Bootstraps the initial component context from a native UNO installation.
::unoidl::com::sun::star::uno::XComponentContext defaultBootstrap_InitialComponentContext()
Bootstraps the initial component context from a native UNO installation.
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
const rtl::Bootstrap * Bootstrap()
OUString String_to_ustring(::System::String ^ str)
inline ::System::Object to_cli(css::uno::Reference< T > const &x)
ExternC const PfnDliHook __pfnDliFailureHook2