namespace net_uno
{ extern"C" {
SAL_DLLPUBLIC_EXPORT IntPtr bootstrap(const Context aContext)
{ try
{ // Bootstrap UNO and start a LibreOffice process if needed
Reference<XComponentContext> xContext(::cppu::bootstrap());
// Get a mapping between the C++ and .NET environments
Environment cpp_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
Environment net_env(u"" UNO_LB_NET ""_ustr, new Context(aContext));
Mapping mapping(cpp_env.get(), net_env.get()); if (!mapping.is())
{
Reference<lang::XComponent> xComp(xContext, UNO_QUERY); if (xComp.is())
{
xComp->dispose();
}
throw RuntimeException(u"could not get mapping between C++ and .NET"_ustr);
}
SAL_DLLPUBLIC_EXPORT IntPtr defaultBootstrap_InitialComponentContext(const sal_Unicode* sIniFile, const sal_Unicode* sParams, const Context aContext)
{ try
{ // Set bootstrap parameters, merged into a single string (at least for now) // to avoid dealing with lifetimes and memory of multiple strings if (sParams)
{
OUString paramsStr(sParams); for (size_t i = 0; i != std::u16string_view::npos;)
{
std::u16string_view name(o3tl::getToken(paramsStr, u'|', i));
OUString key(name.substr(0, name.find_first_of('=')));
OUString val(name.substr(key.getLength() + 1));
::rtl::Bootstrap::set(key, val);
}
}
// Bootstrap UNO
Reference<XComponentContext> xContext; if (sIniFile)
{
xContext = ::cppu::defaultBootstrap_InitialComponentContext(OUString(sIniFile));
} else
{
xContext = ::cppu::defaultBootstrap_InitialComponentContext();
}
// Get a mapping between the C++ and .NET environments
Environment cpp_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
Environment net_env(u"" UNO_LB_NET ""_ustr, new Context(aContext));
Mapping mapping(cpp_env.get(), net_env.get()); if (!mapping.is())
{
Reference<lang::XComponent> xComp(xContext, UNO_QUERY); if (xComp.is())
{
xComp->dispose();
}
throw RuntimeException(u"could not get mapping between C++ and .NET"_ustr);
}