28#include <com/sun/star/script/CannotConvertException.hpp>
36#include <ooo/vba/XHelperInterface.hpp>
44using namespace com::sun::star::bridge::ModelDependent;
50DEFINE_GUID(OID_ServiceManager, 0x82154420, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4);
55DEFINE_GUID(OID_LibreOfficeWriterApplication, 0x82154421, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4);
59DEFINE_GUID(OID_LibreOfficeCalcApplication, 0x82154425, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4);
64 , m_xInstFunction(xInstFunction)
87 hresult = CoRegisterClassObject(
90 CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
94 SAL_INFO(
"extensions.olebridge",
"CoRegisterClassObject(" << *pGuid <<
"): " << WindowsErrorStringFromHRESULT(hresult));
96 return (hresult == NOERROR);
106 if(IsEqualIID(riid, IID_IUnknown))
109 *ppv =
static_cast<IUnknown*
>(
static_cast<IClassFactory*
>(
this));
112 else if (IsEqualIID(riid, IID_IClassFactory))
115 *ppv =
static_cast<IClassFactory*
>(
this);
120 return ResultFromScode(E_NOINTERFACE);
128COM_DECLSPEC_NOTHROW
STDMETHODIMP_(ULONG) OneInstanceOleWrapper::Release()
130 MutexGuard oGuard( Mutex::getGlobalMutex());
141 REFIID riid,
void** ppv)
145 SAL_INFO(
"extensions.olebridge",
"OneInstanceOleWrapper::CreateInstance(" << riid <<
")");
147 HRESULT ret = ResultFromScode(E_UNEXPECTED);
154 rtl_getGlobalProcessId( arId);
161 if (
auto v = o3tl::tryAccess<sal_uIntPtr>(oleAny))
163 VARIANT* pVariant =
reinterpret_cast<VARIANT*
>(*v);
165 if ((pVariant->vt == VT_UNKNOWN) || (pVariant->vt == VT_DISPATCH))
167 SAL_INFO(
"extensions.olebridge",
"OneInstanceOleWrapper::Createbridge: punkVal=" << pVariant->punkVal);
168 ret = pVariant->punkVal->QueryInterface(riid, ppv);
171 VariantClear(pVariant);
172 CoTaskMemFree(pVariant);
204 sal_Int16 sourceModelType,
205 sal_Int16 destModelType)
209 rtl_getGlobalProcessId( arId );
213 if ( seqProcessId == ProcessId)
215 if (sourceModelType ==
UNO)
217 if (destModelType ==
UNO)
220 ret = modelDepObject;
222 else if (destModelType ==
OLE)
225 VARIANT* pVariant =
static_cast<VARIANT*
>(CoTaskMemAlloc(
sizeof(VARIANT)));
226 VariantInit( pVariant);
233 CoTaskMemFree(pVariant);
234 throw IllegalArgumentException();
239 throw IllegalArgumentException();
241 else if (sourceModelType ==
OLE)
243 auto v = o3tl::tryAccess<sal_uIntPtr>(modelDepObject);
246 throw IllegalArgumentException();
248 else if (destModelType ==
OLE)
251 VARIANT* pVariant =
static_cast<VARIANT*
>(CoTaskMemAlloc(
sizeof(VARIANT)));
253 if (NOERROR != VariantCopy(pVariant,
reinterpret_cast<VARIANT*
>(*
v)))
255 CoTaskMemFree(pVariant);
256 throw(IllegalArgumentException());
263 else if (destModelType ==
UNO)
266 VARIANT* pVariant =
reinterpret_cast<VARIANT*
>(*v);
271 catch (
const CannotConvertException & e)
273 throw IllegalArgumentException(
274 e.Message,
nullptr, -1);
278 throw IllegalArgumentException();
282 throw IllegalArgumentException();
291 ? OUString(
"com.sun.star.comp.ole.OleConverter2")
292 : OUString(
"com.sun.star.comp.ole.OleConverterVar1");
304 return css::uno::Sequence<OUString>{
305 "com.sun.star.bridge.OleBridgeSupplier2",
306 "com.sun.star.bridge.oleautomation.BridgeSupplier"};
308 return {
"com.sun.star.bridge.OleBridgeSupplierVar1"};
375 return "com.sun.star.comp.ole.OleClient";
385 return css::uno::Sequence<OUString>{
386 "com.sun.star.bridge.OleObjectFactory",
387 "com.sun.star.bridge.oleautomation.Factory"};
394 IUnknown* pUnknown =
nullptr;
400 o3tl::toW(ServiceSpecifier.getStr()),
406 result = CoCreateInstance(
411 reinterpret_cast<void**
>(&pUnknown));
415 if (pUnknown !=
nullptr)
420 V_VT(&variant) = VT_UNKNOWN;
421 V_UNKNOWN(&variant) = pUnknown;
427 if (
any.getValueTypeClass() == TypeClass_INTERFACE)
483 &OID_ServiceManager );
490 Any aApplication = xHelperInterface->Application();
492 aApplication >>= xApplication;
495 &OID_LibreOfficeWriterApplication );
502 Any aApplication = xHelperInterface->Application();
504 aApplication >>= xApplication;
507 &OID_LibreOfficeCalcApplication );
514 elem->deregisterClass();
522 return "com.sun.star.comp.ole.OleServer";
532 return css::uno::Sequence<OUString>{
533 "com.sun.star.bridge.OleApplicationRegistration",
534 "com.sun.star.bridge.oleautomation.ApplicationRegistration"};
Reference< XBridgeSupplier2 > m_bridgeSupplier
Reference< XInterface > createComWrapperInstance() override
Reference< XInterface > SAL_CALL createInstance(const OUString &ServiceSpecifier) override
Sequence< OUString > SAL_CALL getAvailableServiceNames() override
Reference< XInterface > createUnoWrapperInstance() override
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
Reference< XInterface > SAL_CALL createInstanceWithArguments(const OUString &ServiceSpecifier, const Sequence< Any > &Arguments) override
OleClient(const Reference< XMultiServiceFactory > &smgr)
OUString SAL_CALL getImplementationName() override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Any SAL_CALL createBridge(const Any &modelDepObject, const Sequence< sal_Int8 > &ProcessId, sal_Int16 sourceModelType, sal_Int16 destModelType) override
Reference< XInterface > createComWrapperInstance() override
OUString SAL_CALL getImplementationName() override
virtual ~OleConverter() override
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
OleConverter(const Reference< XMultiServiceFactory > &smgr)
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Reference< XInterface > createUnoWrapperInstance() override
void SAL_CALL initialize(const Sequence< Any > &aArguments) override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
std::list< OneInstanceOleWrapper * > m_wrapperList
bool provideInstance(std::function< const Reference< XInterface >()> xInstFunction, GUID const *guid)
Reference< XBridgeSupplier2 > m_bridgeSupplier
OleServer(const Reference< XMultiServiceFactory > &smgr)
OUString SAL_CALL getImplementationName() override
Reference< XMultiServiceFactory > m_smgr
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
Reference< XBridgeSupplier2 > m_bridgeSupplier
bool registerClass(GUID const *pGuid)
virtual ~OneInstanceOleWrapper()
OneInstanceOleWrapper(const Reference< XMultiServiceFactory > &smgr, std::function< const Reference< XInterface >()> xInstFunction)
STDMETHOD() CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv) override
Reference< XMultiServiceFactory > m_smgr
STDMETHOD() QueryInterface(REFIID riid, void **ppvObj) override
STDMETHOD() LockServer(BOOL fLock) override
std::function< const Reference< XInterface >()> m_xInstFunction
oslInterlockedCount m_refCount
All methods are allowed to throw at least a BridgeRuntimeError.
void anyToVariant(VARIANT *pVariant, const Any &rAny)
converts only into oleautomation types, that is there is no VT_I1, VT_UI2, VT_UI4 a sal_Unicode chara...
const sal_uInt8 m_nUnoWrapperClass
void variantToAny(const VARIANT *pVariant, Any &rAny, bool bReduceValueRange=true)
Reference< XMultiServiceFactory > m_smgr
Reference< XMultiServiceFactory > m_smgrRemote
const sal_uInt8 m_nComWrapperClass
Sequence< PropertyValue > aArguments
#define SAL_INFO(area, stream)
MetadataImporterPluginType * result
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void o2u_attachCurrentThread()
const wchar_t *typedef BOOL
DEFINE_GUID(OID_ServiceManager, 0x82154420, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4)
COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) OneInstanceOleWrapper
#define UNO_OBJECT_WRAPPER_REMOTE_OPT
#define INTERFACE_OLE_WRAPPER_IMPL