24#include <osl/diagnose.h>
25#include <osl/doublecheckedlocking.h>
26#include <osl/thread.h>
30#include <com/sun/star/script/CannotConvertException.hpp>
31#include <com/sun/star/script/FailReason.hpp>
32#include <com/sun/star/beans/XMaterialHolder.hpp>
33#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
34#include <com/sun/star/script/XInvocation.hpp>
35#include <com/sun/star/bridge/ModelDependent.hpp>
37#include <com/sun/star/bridge/oleautomation/NamedArgument.hpp>
38#include <com/sun/star/bridge/oleautomation/PropertyPutArgument.hpp>
41#include <typelib/typedescription.hxx>
43#include <rtl/ustring.hxx>
56using namespace com::sun::star::bridge::ModelDependent;
60#define JSCRIPT_ID_PROPERTY L"_environment"
61#define JSCRIPT_ID L"jscript"
85 m_pxIdlClass( nullptr), m_eJScript( JScriptUndefined),
86 m_bComTlbIndexInit(false), m_bHasDfltMethod(false), m_bHasDfltProperty(false)
96#if OSL_DEBUG_LEVEL > 0
105 sal_uIntPtr adapter= it->second;
130 return WeakImplHelper<XBridgeSupplier2,
131 XInitialization, XAutomationObject, XDefaultProperty, XDefaultMethod, XDirectInvocation, XAutomationInvocation >
::queryInterface(
t);
151 getPropDesc(aPropertyName, & aDescGet, & aDescPut, & aVarDesc);
154 OUString msg(
"[automation bridge]Property \"" + aPropertyName +
155 "\" is not supported");
156 throw UnknownPropertyException(msg);
163 throw css::lang::WrappedTargetRuntimeException(
"[automation bridge] unexpected exception in "
164 "IUnknownWrapper::invokeGetProperty ! Message : \n " +
181 getPropDesc(aPropertyName, & aDescGet, & aDescPut, & aVarDesc);
184 OUString msg(
"[automation bridge]Property \"" + aPropertyName +
185 "\" is not supported");
186 throw UnknownPropertyException(msg);
193 throw css::lang::WrappedTargetRuntimeException(
"[automation bridge] unexpected exception in "
194 "IUnknownWrapper::invokePutProperty ! Message : \n" +
209 "[automation bridge] The object does not have an IDispatch interface");
218 TypeDescription methodDesc;
235 catch (
const IllegalArgumentException &)
239 catch (
const CannotConvertException &)
250 throw css::lang::WrappedTargetRuntimeException(
"[automation bridge] unexpected exception in "
251 "IUnknownWrapper::invoke ! Message : \n" +
259 "IUnknownWrapper::Invoke !");
270 "[automation bridge] The object does not have an IDispatch interface");
280 getPropDesc(aPropertyName, & aDescGet, & aDescPut, & aVarDesc);
282 if ( ! aDescPut && ! aDescGet && ! aVarDesc)
284 OUString msg(
"[automation bridge]Property \"" + aPropertyName +
285 "\" is not supported");
286 throw UnknownPropertyException(msg);
289 if ( (! aDescPut && aDescGet)
290 || (aVarDesc && aVarDesc->wVarFlags == VARFLAG_FREADONLY) )
293 SAL_WARN(
"extensions.olebridge",
"[automation bridge] Property " << aPropertyName <<
" is read-only");
299 DISPPARAMS dispparams;
301 CComVariant varRefArg;
302 CComVariant varResult;
304 unsigned int uArgErr;
307 DISPID dispidPut= DISPID_PROPERTYPUT;
308 dispparams.rgdispidNamedArgs = &dispidPut;
309 dispparams.cArgs = 1;
310 dispparams.cNamedArgs = 1;
311 dispparams.rgvarg = & varArg;
313 OSL_ASSERT(aDescPut || aVarDesc);
317 INVOKEKIND invkind = INVOKE_PROPERTYPUT;
323 dispid = aDescPut->memid;
324 invkind = aDescPut->invkind;
329 dispid = aVarDesc->memid;
330 if (vt == VT_UNKNOWN || vt == VT_DISPATCH ||
333 invkind = INVOKE_PROPERTYPUTREF;
343 varArg.byref = & varRefArg;
345 varArg.byref = & varRefArg.decVal;
347 varArg.byref = & varRefArg.byref;
354 hr =
m_spDispatch->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, ::sal::static_int_cast< WORD, INVOKEKIND >( invkind ),
355 &dispparams, & varResult, & excepinfo, &uArgErr);
362 case DISP_E_BADPARAMCOUNT:
365 case DISP_E_BADVARTYPE:
368 case DISP_E_EXCEPTION:
369 throw InvocationTargetException();
371 case DISP_E_MEMBERNOTFOUND:
372 throw UnknownPropertyException();
374 case DISP_E_NONAMEDARGS:
377 case DISP_E_OVERFLOW:
378 throw CannotConvertException(
"call to OLE object failed",
static_cast<XInterface*
>(
379 static_cast<XWeak*
>(
this)), TypeClass_UNKNOWN, FailReason::OUT_OF_RANGE, uArgErr);
381 case DISP_E_PARAMNOTFOUND:
382 throw IllegalArgumentException(
"call to OLE object failed",
static_cast<XInterface*
>(
383 static_cast<XWeak*
>(
this)), ::sal::static_int_cast< sal_Int16, unsigned int >( uArgErr )) ;
385 case DISP_E_TYPEMISMATCH:
386 throw CannotConvertException(
"call to OLE object failed",
static_cast<XInterface*
>(
387 static_cast<XWeak*
>(
this)), TypeClass_UNKNOWN, FailReason::UNKNOWN, ::sal::static_int_cast< sal_Int16, unsigned int >( uArgErr ));
389 case DISP_E_UNKNOWNINTERFACE:
392 case DISP_E_UNKNOWNLCID:
395 case DISP_E_PARAMNOTOPTIONAL:
396 throw CannotConvertException(
"call to OLE object failed",
static_cast<XInterface*
>(
397 static_cast<XWeak*
>(
this)) , TypeClass_UNKNOWN, FailReason::NO_DEFAULT_AVAILABLE, uArgErr);
404 catch (
const CannotConvertException &)
408 catch (
const UnknownPropertyException &)
419 throw css::lang::WrappedTargetRuntimeException(
"[automation bridge] unexpected exception in "
420 "IUnknownWrapper::setValue ! Message : \n" +
428 "[automation bridge] unexpected exception in "
429 "IUnknownWrapper::setValue !");
438 "[automation bridge] The object does not have an IDispatch interface");
454 if ( aPropertyName ==
"$GetTypeName" )
461 if ( SUCCEEDED( pInfo->GetDocumentation( -1, &
sName,
nullptr,
nullptr,
nullptr ) ) )
463 OUString sTmp( o3tl::toU(LPCOLESTR(
sName)));
464 if ( sTmp.startsWith(
"_") )
468 CComPtr< ITypeLib > pTypeLib;
470 if ( SUCCEEDED( pInfo->GetContainingTypeLib( &pTypeLib.p, &
index )) )
472 if ( SUCCEEDED( pTypeLib->GetDocumentation( -1, &
sName,
nullptr,
nullptr,
nullptr ) ) )
474 OUString sLibName( o3tl::toU(LPCOLESTR(
sName)));
488 getPropDesc(aPropertyName, & aDescGet, & aDescPut, & aVarDesc);
489 if ( ! aDescGet && ! aDescPut && ! aVarDesc)
492 OUString msg(
"[automation bridge]Property \"" + aPropertyName +
493 "\" is not supported");
494 throw UnknownPropertyException(msg);
497 OSL_ASSERT( aDescGet || ! aDescPut);
500 DISPPARAMS dispparams = {
nullptr,
nullptr, 0, 0};
501 CComVariant varResult;
503 unsigned int uArgErr;
506 dispid = aDescGet->memid;
508 dispid = aVarDesc->memid;
510 dispid = aDescPut->memid;
515 DISPATCH_PROPERTYGET,
526 TypeDescription attrInfo;
539 case DISP_E_BADPARAMCOUNT:
540 case DISP_E_BADVARTYPE:
541 case DISP_E_EXCEPTION:
544 case DISP_E_MEMBERNOTFOUND:
545 throw UnknownPropertyException(OUString(o3tl::toU(excepinfo.bstrDescription)));
552 catch (
const UnknownPropertyException& )
563 throw css::lang::WrappedTargetRuntimeException(
"[automation bridge] unexpected exception in "
564 "IUnknownWrapper::getValue ! Message : \n" +
571 "[automation bridge] unexpected exception in "
572 "IUnknownWrapper::getValue !");
582 "[automation bridge] The object does not have an IDispatch interface");
600 if ((aDescGet && aDescGet->cParams > 0)
601 || (aDescPut && aDescPut->cParams > 0))
614 throw css::lang::WrappedTargetRuntimeException(
"[automation bridge] unexpected exception in "
615 "IUnknownWrapper::hasMethod ! Message : \n" +
622 "IUnknownWrapper::hasMethod !");
632 "IDispatch interface");
665 throw css::lang::WrappedTargetRuntimeException(
"[automation bridge] unexpected exception in "
666 "IUnknownWrapper::hasProperty ! Message : \n" +
674 "IUnknownWrapper::hasProperty !");
681 sal_Int16 destModelType )
687 (sourceModelType ==
UNO) &&
688 (destModelType ==
OLE) &&
689 (modelDepObject.getValueTypeClass() == TypeClass_INTERFACE)
697 VARIANT* pVariant =
static_cast<VARIANT*
>(CoTaskMemAlloc(
sizeof(VARIANT)));
699 VariantInit(pVariant);
702 pVariant->vt = VT_DISPATCH;
704 pVariant->pdispVal->AddRef();
708 pVariant->vt = VT_UNKNOWN;
710 pVariant->punkVal->AddRef();
733 sal_Int32 parameterCount= Params.getLength();
734 sal_Int32 outParameterCount= 0;
735 typelib_InterfaceMethodTypeDescription* pMethod=
nullptr;
736 TypeDescription methodDesc;
743 std::unique_ptr<CComVariant[]> sarParams;
744 std::unique_ptr<CComVariant[]> sarParamsRef;
745 CComVariant *pVarParams=
nullptr;
746 CComVariant *pVarParamsRef=
nullptr;
751 pMethod =
reinterpret_cast<typelib_InterfaceMethodTypeDescription*
>(methodDesc.get());
752 parameterCount = pMethod->nParams;
755 if( pMethod->nParams > 0)
757 sarParams.reset(
new CComVariant[ parameterCount]);
758 pVarParams = sarParams.get();
764 for( sal_Int32
i=0;
i < parameterCount;
i++)
766 if( pMethod->pParams[
i].bOut)
772 sarParamsRef.reset(
new CComVariant[outParameterCount]);
773 pVarParamsRef = sarParamsRef.get();
775 sal_Int32 outParamIndex=0;
779 for(
i= 0;
i < parameterCount;
i++)
782 if( pMethod->pParams[
i].bIn && ! pMethod->pParams[
i].bOut)
784 anyToVariant( &pVarParams[parameterCount -
i -1], Params.getConstArray()[
i]);
787 else if( pMethod->pParams[
i].bOut )
790 if(pMethod->pParams[
i].bIn)
793 pVarParamsRef[outParamIndex] = var;
796 switch( pMethod->pParams[
i].pTypeRef->eTypeClass)
798 case typelib_TypeClass_INTERFACE:
799 case typelib_TypeClass_STRUCT:
800 if( ! pMethod->pParams[
i].bIn)
802 pVarParamsRef[ outParamIndex].vt= VT_DISPATCH;
803 pVarParamsRef[ outParamIndex].pdispVal=
nullptr;
805 pVarParams[parameterCount -
i -1].vt = VT_DISPATCH |
VT_BYREF;
806 pVarParams[parameterCount -
i -1].ppdispVal= &pVarParamsRef[outParamIndex].pdispVal;
808 case typelib_TypeClass_ENUM:
809 case typelib_TypeClass_LONG:
810 case typelib_TypeClass_UNSIGNED_LONG:
811 if( ! pMethod->pParams[
i].bIn)
813 pVarParamsRef[ outParamIndex].vt =
VT_I4;
814 pVarParamsRef[ outParamIndex].lVal = 0;
817 pVarParams[parameterCount -
i -1].plVal= &pVarParamsRef[outParamIndex].lVal;
819 case typelib_TypeClass_SEQUENCE:
820 if( ! pMethod->pParams[
i].bIn)
823 pVarParamsRef[ outParamIndex].parray=
nullptr;
826 pVarParams[parameterCount -
i -1].pparray= &pVarParamsRef[outParamIndex].parray;
828 case typelib_TypeClass_ANY:
829 if( ! pMethod->pParams[
i].bIn)
831 pVarParamsRef[ outParamIndex].vt =
VT_EMPTY;
832 pVarParamsRef[ outParamIndex].lVal = 0;
835 pVarParams[parameterCount -
i -1].pvarVal = &pVarParamsRef[outParamIndex];
837 case typelib_TypeClass_BOOLEAN:
838 if( ! pMethod->pParams[
i].bIn)
840 pVarParamsRef[ outParamIndex].vt =
VT_BOOL;
841 pVarParamsRef[ outParamIndex].boolVal = 0;
844 pVarParams[parameterCount -
i -1].pboolVal =
845 & pVarParamsRef[outParamIndex].boolVal;
848 case typelib_TypeClass_STRING:
849 if( ! pMethod->pParams[
i].bIn)
851 pVarParamsRef[ outParamIndex].vt =
VT_BSTR;
852 pVarParamsRef[ outParamIndex].bstrVal=
nullptr;
855 pVarParams[parameterCount -
i -1].pbstrVal=
856 & pVarParamsRef[outParamIndex].bstrVal;
859 case typelib_TypeClass_FLOAT:
860 if( ! pMethod->pParams[
i].bIn)
862 pVarParamsRef[ outParamIndex].vt =
VT_R4;
863 pVarParamsRef[ outParamIndex].fltVal= 0;
866 pVarParams[parameterCount -
i -1].pfltVal =
867 & pVarParamsRef[outParamIndex].fltVal;
869 case typelib_TypeClass_DOUBLE:
870 if( ! pMethod->pParams[
i].bIn)
872 pVarParamsRef[ outParamIndex].vt =
VT_R8;
873 pVarParamsRef[ outParamIndex].dblVal= 0;
876 pVarParams[parameterCount -
i -1].pdblVal=
877 & pVarParamsRef[outParamIndex].dblVal;
879 case typelib_TypeClass_BYTE:
880 if( ! pMethod->pParams[
i].bIn)
882 pVarParamsRef[ outParamIndex].vt =
VT_UI1;
883 pVarParamsRef[ outParamIndex].bVal= 0;
886 pVarParams[parameterCount -
i -1].pbVal=
887 & pVarParamsRef[outParamIndex].bVal;
889 case typelib_TypeClass_CHAR:
890 case typelib_TypeClass_SHORT:
891 case typelib_TypeClass_UNSIGNED_SHORT:
892 if( ! pMethod->pParams[
i].bIn)
894 pVarParamsRef[ outParamIndex].vt =
VT_I2;
895 pVarParamsRef[ outParamIndex].iVal = 0;
898 pVarParams[parameterCount -
i -1].piVal=
899 & pVarParamsRef[outParamIndex].iVal;
903 if( ! pMethod->pParams[
i].bIn)
905 pVarParamsRef[ outParamIndex].vt =
VT_EMPTY;
906 pVarParamsRef[ outParamIndex].lVal = 0;
909 pVarParams[parameterCount -
i -1].pvarVal =
910 & pVarParamsRef[outParamIndex];
916 catch (IllegalArgumentException & e)
918 e.ArgumentPosition = ::sal::static_int_cast< sal_Int16, int >(
i );
921 catch (CannotConvertException & e)
932 for( ;
i< parameterCount;
i++)
935 if( pMethod->pParams[
i].bIn && ! pMethod->pParams[
i].bOut)
937 anyToVariant( &pVarParams[parameterCount -
i -1], Params.getConstArray()[
i]);
940 else if( pMethod->pParams[
i].bOut )
942 CComObject<JScriptOutParam>* pParamObject;
943 if( !SUCCEEDED( CComObject<JScriptOutParam>::CreateInstance( &pParamObject)))
946 "[automation bridge]IUnknownWrapper::"
947 "invokeWithDispIdUnoTlb\n"
948 "Could not create out parameter at index: " +
949 OUString::number(
static_cast<sal_Int32
>(
i)));
952 CComPtr<IUnknown> pUnk(pParamObject->GetUnknown());
953 CComQIPtr<IDispatch> pDisp( pUnk);
955 pVarParams[ parameterCount -
i -1].vt= VT_DISPATCH;
956 pVarParams[ parameterCount -
i -1].pdispVal= pDisp;
957 pVarParams[ parameterCount -
i -1].pdispVal->AddRef();
959 if( pMethod->pParams[
i].bIn )
961 CComVariant varParam;
963 CComDispatchDriver dispDriver( pDisp);
964 if(FAILED( dispDriver.PutPropertyByName( L
"0", &varParam)))
966 "[automation bridge]IUnknownWrapper::"
967 "invokeWithDispIdUnoTlb\n"
968 "Could not set property \"0\" for the in/out "
975 catch (IllegalArgumentException & e)
977 e.ArgumentPosition = ::sal::static_int_cast< sal_Int16, int >(
i );
980 catch (CannotConvertException & e)
997 CComVariant varResult;
999 unsigned int uArgErr;
1000 DISPPARAMS dispparams= { pVarParams,
nullptr,
static_cast<UINT
>(parameterCount), 0};
1008 LOCALE_USER_DEFAULT,
1018 if( outParameterCount && pMethod)
1020 OutParamIndex.realloc( outParameterCount);
1021 auto pOutParamIndex = OutParamIndex.getArray();
1022 OutParam.realloc( outParameterCount);
1023 auto pOutParam = OutParam.getArray();
1024 sal_Int32 outIndex=0;
1028 for( ;
i < parameterCount;
i++)
1030 if( pMethod->pParams[
i].bOut )
1032 pOutParamIndex[outIndex]=
static_cast<sal_Int16
>(
i);
1034 if( !bJScriptObject)
1037 Type(pMethod->pParams[
i].pTypeRef),
false);
1038 pOutParam[outIndex++]= outAny;
1042 if( pVarParams[
i].vt == VT_DISPATCH)
1044 CComDispatchDriver pDisp( pVarParams[
i].pdispVal);
1048 if( SUCCEEDED( pDisp.GetPropertyByName( L
"0", &varOut)))
1051 Type(pMethod->pParams[parameterCount - 1 -
i].pTypeRef),
false);
1052 pOutParam[outParameterCount - 1 - outIndex++]= outAny;
1064 if( !bConvRet)
break;
1067 catch(IllegalArgumentException & e)
1069 e.ArgumentPosition = ::sal::static_int_cast< sal_Int16, int >(
i );
1072 catch(CannotConvertException & e)
1074 e.ArgumentIndex =
i;
1088 catch (IllegalArgumentException & e)
1091 "[automation bridge]IUnknownWrapper::invokeWithDispIdUnoTlb\n"
1092 "Could not convert return value! \n Message: \n" + e.Message;
1095 catch (CannotConvertException & e)
1098 "[automation bridge]IUnknownWrapper::invokeWithDispIdUnoTlb\n"
1099 "Could not convert return value! \n Message: \n" + e.Message;
1106 throw CannotConvertException(
"Call to COM object failed. Conversion of return or out value failed",
1108 FailReason::UNKNOWN, 0);
1114 case DISP_E_BADPARAMCOUNT:
1115 throw IllegalArgumentException();
1117 case DISP_E_BADVARTYPE:
1120 case DISP_E_EXCEPTION:
1121 throw InvocationTargetException();
1123 case DISP_E_MEMBERNOTFOUND:
1124 throw IllegalArgumentException();
1126 case DISP_E_NONAMEDARGS:
1127 throw IllegalArgumentException();
1129 case DISP_E_OVERFLOW:
1130 throw CannotConvertException(
"call to OLE object failed",
static_cast<XInterface*
>(
1131 static_cast<XWeak*
>(
this)), TypeClass_UNKNOWN, FailReason::OUT_OF_RANGE, uArgErr);
1133 case DISP_E_PARAMNOTFOUND:
1134 throw IllegalArgumentException(
"call to OLE object failed",
static_cast<XInterface*
>(
1135 static_cast<XWeak*
>(
this)), ::sal::static_int_cast< sal_Int16, unsigned int >( uArgErr ));
1137 case DISP_E_TYPEMISMATCH:
1138 throw CannotConvertException(
"call to OLE object failed",
static_cast<XInterface*
>(
1139 static_cast<XWeak*
>(
this)) , TypeClass_UNKNOWN, FailReason::UNKNOWN, uArgErr);
1141 case DISP_E_UNKNOWNINTERFACE:
1144 case DISP_E_UNKNOWNLCID:
1147 case DISP_E_PARAMNOTOPTIONAL:
1148 throw CannotConvertException(
"call to OLE object failed",
static_cast<XInterface*
>(
1149 static_cast<XWeak*
>(
this)), TypeClass_UNKNOWN, FailReason::NO_DEFAULT_AVAILABLE, uArgErr);
1175 ITypeInfo* pType =
nullptr;
1193 CComBSTR defaultMemberName;
1194 if ( SUCCEEDED( pType->GetDocumentation(0, &defaultMemberName,
nullptr,
nullptr,
nullptr ) ) )
1196 OUString usName(o3tl::toU(LPCOLESTR(defaultMemberName)));
1201 getPropDesc( usName, & aDescGet, & aDescPut, & aVarDesc);
1203 if ( !aDescGet && !aDescPut )
1207 throw BridgeRuntimeError(
"[automation bridge]IUnknownWrapper::initialize() Failed to get Function or Property desc. for " + usName );
1217 if ( aDescPut || ( aDescGet && aDescGet->cParams == 0 ) )
1219 if ( aDescGet->cParams > 0 )
1232 throw css::lang::WrappedTargetRuntimeException(
1233 "[automation bridge] unexpected exception in IUnknownWrapper::initialize() error message: \n" + e.Message,
1248 "[automation bridge] The object does not have an IDispatch interface");
1254 throw IllegalArgumentException(
1255 "[automation bridge] The object does not have a function or property "
1258 CComVariant varResult;
1260 unsigned int uArgErr = 0;
1261 INVOKEKIND pInvkinds[2];
1262 pInvkinds[0] = INVOKE_FUNC;
1263 pInvkinds[1] = aParams.getLength() ? INVOKE_PROPERTYPUT : INVOKE_PROPERTYGET;
1264 HRESULT hInvRes = E_FAIL;
1267 for ( sal_Int32 nStep = 0; FAILED( hInvRes ) && nStep < 2; nStep++ )
1269 DISPPARAMS dispparams = {
nullptr,
nullptr, 0, 0};
1271 std::unique_ptr<DISPID[]> arDispidNamedArgs;
1272 std::unique_ptr<CComVariant[]> ptrArgs;
1273 std::unique_ptr<CComVariant[]> ptrRefArgs;
1274 CComVariant * arArgs =
nullptr;
1275 CComVariant * arRefArgs =
nullptr;
1277 dispparams.cArgs = aParams.getLength();
1282 dispparams.cNamedArgs ++;
1285 if ( dispparams.cNamedArgs > 0
1286 && ( dispparams.cNamedArgs != 1 || pInvkinds[nStep] != INVOKE_PROPERTYPUT ) )
1288 int nSizeAr = dispparams.cNamedArgs + 1;
1289 if ( pInvkinds[nStep] == INVOKE_PROPERTYPUT )
1290 nSizeAr = dispparams.cNamedArgs;
1292 std::unique_ptr<OLECHAR*[]> saNames(
new OLECHAR*[nSizeAr]);
1293 OLECHAR ** pNames = saNames.get();
1294 pNames[0] =
const_cast<OLECHAR*
>(o3tl::toW(
aName.getStr()));
1297 for (
size_t nInd = 0; nInd < dispparams.cArgs; nInd++ )
1299 if (
auto v = o3tl::tryAccess<NamedArgument>(aParams[nInd]))
1301 const NamedArgument& arg = *
v;
1306 pNames[nSizeAr - 1 - cNamedArg++] =
const_cast<OLECHAR*
>(o3tl::toW(arg.Name.getStr()));
1310 arDispidNamedArgs.reset(
new DISPID[nSizeAr] );
1311 HRESULT
hr =
getTypeInfo()->GetIDsOfNames( pNames, nSizeAr, arDispidNamedArgs.get() );
1312 if (
hr == E_NOTIMPL )
1313 hr =
m_spDispatch->GetIDsOfNames(IID_NULL, pNames, nSizeAr, LOCALE_USER_DEFAULT, arDispidNamedArgs.get() );
1315 if ( SUCCEEDED(
hr ) )
1317 if ( pInvkinds[nStep] == DISPATCH_PROPERTYPUT )
1319 DISPID* arIDs = arDispidNamedArgs.get();
1320 arIDs[0] = DISPID_PROPERTYPUT;
1321 dispparams.rgdispidNamedArgs = arIDs;
1325 DISPID* arIDs = arDispidNamedArgs.get();
1326 dispparams.rgdispidNamedArgs = & arIDs[1];
1329 else if (
hr == DISP_E_UNKNOWNNAME)
1331 throw IllegalArgumentException(
1332 "[automation bridge]One of the named arguments is wrong!",
1337 throw InvocationTargetException(
1338 "[automation bridge] ITypeInfo::GetIDsOfNames returned error "
1344 ptrArgs.reset(
new CComVariant[dispparams.cArgs]);
1345 ptrRefArgs.reset(
new CComVariant[dispparams.cArgs]);
1346 arArgs = ptrArgs.get();
1347 arRefArgs = ptrRefArgs.get();
1352 sal_Int32 revIndex = 0;
1353 for ( nInd = 0; nInd < sal_Int32(dispparams.cArgs); nInd++)
1355 revIndex = dispparams.cArgs - nInd - 1;
1356 arRefArgs[revIndex].byref =
nullptr;
1358 if ( nInd < aParams.getLength() )
1359 anyArg = aParams.getConstArray()[nInd];
1364 PropertyPutArgument arg;
1371 NamedArgument aNamedArgument;
1372 anyArg >>= aNamedArgument;
1373 anyArg = aNamedArgument.Value;
1376 if ( nInd < aParams.getLength() && anyArg.getValueTypeClass() != TypeClass_VOID )
1383 arArgs[revIndex].scode = DISP_E_PARAMNOTFOUND;
1387 catch (IllegalArgumentException & e)
1389 e.ArgumentPosition = ::sal::static_int_cast< sal_Int16, sal_Int32 >( nInd );
1392 catch (CannotConvertException & e)
1394 e.ArgumentIndex = nInd;
1398 dispparams.rgvarg = arArgs;
1402 LOCALE_USER_DEFAULT,
1403 ::sal::static_int_cast< WORD, INVOKEKIND >( pInvkinds[nStep] ),
1411 if ( SUCCEEDED( hInvRes ) )
1421 case DISP_E_BADPARAMCOUNT:
1422 throw IllegalArgumentException(
"[automation bridge] Wrong "
1423 "number of arguments. Object returned DISP_E_BADPARAMCOUNT.",
1426 case DISP_E_BADVARTYPE:
1428 "arguments have the wrong type. Object returned "
1429 "DISP_E_BADVARTYPE.",
nullptr);
1431 case DISP_E_EXCEPTION:
1432 message = OUString::Concat(
"[automation bridge]: ")
1433 + std::u16string_view(o3tl::toU(excepinfo.bstrDescription),
1434 ::SysStringLen(excepinfo.bstrDescription));
1437 case DISP_E_MEMBERNOTFOUND:
1438 message =
"[automation bridge]: A function with the name \""
1439 +
aName +
"\" is not supported. Object returned "
1440 "DISP_E_MEMBERNOTFOUND.";
1441 throw IllegalArgumentException(message,
nullptr, 0);
1443 case DISP_E_NONAMEDARGS:
1444 throw IllegalArgumentException(
"[automation bridge] Object "
1445 "returned DISP_E_NONAMEDARGS",
nullptr, ::sal::static_int_cast< sal_Int16, unsigned int >( uArgErr ));
1447 case DISP_E_OVERFLOW:
1448 throw CannotConvertException(
"[automation bridge] Call failed.",
1450 static_cast<XWeak*
>(
this)), TypeClass_UNKNOWN, FailReason::OUT_OF_RANGE, uArgErr);
1452 case DISP_E_PARAMNOTFOUND:
1453 throw IllegalArgumentException(
"[automation bridge]Call failed."
1454 "Object returned DISP_E_PARAMNOTFOUND.",
1455 nullptr, ::sal::static_int_cast< sal_Int16, unsigned int >( uArgErr ));
1457 case DISP_E_TYPEMISMATCH:
1458 throw CannotConvertException(
"[automation bridge] Call failed. "
1459 "Object returned DISP_E_TYPEMISMATCH",
1461 static_cast<XWeak*
>(
this)) , TypeClass_UNKNOWN, FailReason::UNKNOWN, uArgErr);
1463 case DISP_E_UNKNOWNINTERFACE:
1465 "Object returned DISP_E_UNKNOWNINTERFACE.",
nullptr);
1467 case DISP_E_UNKNOWNLCID:
1469 "Object returned DISP_E_UNKNOWNLCID.",
nullptr);
1471 case DISP_E_PARAMNOTOPTIONAL:
1472 throw CannotConvertException(
"[automation bridge] Call failed."
1473 "Object returned DISP_E_PARAMNOTOPTIONAL",
1474 static_cast<XInterface*
>(
static_cast<XWeak*
>(
this)),
1475 TypeClass_UNKNOWN, FailReason::NO_DEFAULT_AVAILABLE, uArgErr);
1491 "[automation bridge] The object does not have an IDispatch interface");
1532 if( pMember->eTypeClass == typelib_TypeClass_INTERFACE_METHOD )
1533 methodInfo= pMember;
1543 if( pMember->eTypeClass == typelib_TypeClass_INTERFACE_ATTRIBUTE )
1545 attributeInfo=
reinterpret_cast<typelib_InterfaceAttributeTypeDescription*
>(pMember)->pAttributeTypeRef;
1551 TypeDescription ret;
1553 for(
auto const & rType : std::as_const(
m_seqTypes) )
1555 TypeDescription _curDesc( rType );
1556 _curDesc.makeComplete();
1557 typelib_InterfaceTypeDescription * pInterface=
reinterpret_cast<typelib_InterfaceTypeDescription*
>(_curDesc.get());
1560 typelib_InterfaceMemberTypeDescription* pMember=
nullptr;
1562 for(
int j=0; j < pInterface->nAllMembers; j++)
1564 typelib_TypeDescriptionReference* pTypeRefMember = pInterface->ppAllMembers[j];
1566 TYPELIB_DANGER_GET( &pDescMember, pTypeRefMember);
1568 typelib_InterfaceMemberTypeDescription* pInterfaceMember=
1569 reinterpret_cast<typelib_InterfaceMemberTypeDescription*
>(pDescMember);
1570 if( OUString( pInterfaceMember->pMemberName) ==
sName)
1572 pMember= pInterfaceMember;
1575 TYPELIB_DANGER_RELEASE( pDescMember);
1580 ret= &pMember->aBase;
1581 TYPELIB_DANGER_RELEASE( &pMember->aBase);
1641 const OUString& sFuncName,
1649 DISPPARAMS dispparams = {
nullptr,
nullptr, 0, 0};
1650 CComVariant varResult;
1652 unsigned int uArgErr;
1654 sal_Int32 nUnoArgs = Params.getLength();
1655 DISPID idPropertyPut = DISPID_PROPERTYPUT;
1656 std::unique_ptr<DISPID[]> arDispidNamedArgs;
1657 std::unique_ptr<CComVariant[]> ptrArgs;
1658 std::unique_ptr<CComVariant[]> ptrRefArgs;
1659 CComVariant * arArgs =
nullptr;
1660 CComVariant * arRefArgs =
nullptr;
1661 sal_Int32 revIndex = 0;
1665 if (aFuncDesc->invkind == INVOKE_PROPERTYPUT
1666 || aFuncDesc->invkind == INVOKE_PROPERTYPUTREF)
1667 dispparams.rgdispidNamedArgs = & idPropertyPut;
1670 for (
int iParam = 0; iParam < nUnoArgs; iParam ++)
1672 const Any & curArg = Params[iParam];
1674 dispparams.cNamedArgs ++;
1680 if (aFuncDesc->invkind == DISPATCH_PROPERTYPUT
1681 || aFuncDesc->invkind == DISPATCH_PROPERTYPUTREF)
1682 dispparams.cNamedArgs ++;
1685 if (aFuncDesc->cParamsOpt == -1)
1689 dispparams.cArgs = nUnoArgs;
1695 if (dispparams.cNamedArgs)
1696 dispparams.cArgs = nUnoArgs;
1698 dispparams.cArgs = aFuncDesc->cParams;
1702 if (::sal::static_int_cast< sal_uInt32, int >( nUnoArgs ) > dispparams.cArgs)
1704 throw IllegalArgumentException(
1705 "[automation bridge] There are too many arguments for this method",
1713 if (dispparams.cNamedArgs > 0 &&
1714 ! (dispparams.cNamedArgs == 1 &&
1715 (aFuncDesc->invkind == INVOKE_PROPERTYPUT ||
1716 aFuncDesc->invkind == INVOKE_PROPERTYPUTREF)))
1723 int nSizeAr = dispparams.cNamedArgs + 1;
1724 if (aFuncDesc->invkind == INVOKE_PROPERTYPUT
1725 || aFuncDesc->invkind == INVOKE_PROPERTYPUTREF)
1727 nSizeAr = dispparams.cNamedArgs;
1730 std::unique_ptr<OLECHAR*[]> saNames(
new OLECHAR*[nSizeAr]);
1731 OLECHAR ** arNames = saNames.get();
1732 arNames[0] =
const_cast<OLECHAR*
>(o3tl::toW(sFuncName.getStr()));
1735 for (
size_t iParams = 0; iParams < dispparams.cArgs; iParams ++)
1737 const Any & curArg = Params[iParams];
1738 if (
auto v = o3tl::tryAccess<NamedArgument>(curArg))
1740 const NamedArgument& arg = *
v;
1744 arNames[nSizeAr - 1 - cNamedArg++] =
const_cast<OLECHAR*
>(o3tl::toW(arg.Name.getStr()));
1750 arDispidNamedArgs.reset(
new DISPID[nSizeAr]);
1752 arDispidNamedArgs.get());
1753 if (
hr == E_NOTIMPL )
1754 hr =
m_spDispatch->GetIDsOfNames(IID_NULL, arNames, nSizeAr, LOCALE_USER_DEFAULT, arDispidNamedArgs.get() );
1760 if (aFuncDesc->invkind == DISPATCH_PROPERTYPUT
1761 || aFuncDesc->invkind == DISPATCH_PROPERTYPUTREF)
1766 DISPID* arIDs = arDispidNamedArgs.get();
1767 arIDs[0] = DISPID_PROPERTYPUT;
1768 dispparams.rgdispidNamedArgs = arIDs;
1774 DISPID* arIDs = arDispidNamedArgs.get();
1775 dispparams.rgdispidNamedArgs = & arIDs[1];
1778 else if (
hr == DISP_E_UNKNOWNNAME)
1780 throw IllegalArgumentException(
1781 "[automation bridge]One of the named arguments is wrong!",
1786 throw InvocationTargetException(
1787 "[automation bridge] ITypeInfo::GetIDsOfNames returned error "
1793 ptrArgs.reset(
new CComVariant[dispparams.cArgs]);
1794 ptrRefArgs.reset(
new CComVariant[dispparams.cArgs]);
1795 arArgs = ptrArgs.get();
1796 arRefArgs = ptrRefArgs.get();
1799 for (
i = 0; i < static_cast<sal_Int32>(dispparams.cArgs);
i++)
1801 revIndex= dispparams.cArgs -
i -1;
1802 arRefArgs[revIndex].byref=
nullptr;
1805 anyArg= Params.getConstArray()[
i];
1807 unsigned short paramFlags = PARAMFLAG_FOPT | PARAMFLAG_FIN;
1809 if (aFuncDesc->cParamsOpt != -1 || aFuncDesc->cParams != (
i + 1))
1811 paramFlags = aFuncDesc->lprgelemdescParam[
i].paramdesc.wParamFlags;
1819 if (
i >= nUnoArgs && !(paramFlags & PARAMFLAG_FOPT))
1821 throw IllegalArgumentException(
1822 (
"ole automation bridge: The called function expects an argument at position: "
1823 + OUString::number(
i) +
" (index starting at 0)."),
1830 PropertyPutArgument arg;
1837 NamedArgument aNamedArgument;
1838 anyArg >>= aNamedArgument;
1839 anyArg = aNamedArgument.Value;
1842 if (paramFlags & PARAMFLAG_FOUT &&
1843 ! (paramFlags & PARAMFLAG_FIN) )
1845 VARTYPE
type = ::sal::static_int_cast< VARTYPE, int >( varType ^
VT_BYREF );
1848 arRefArgs[revIndex].vt=
type;
1854 arRefArgs[revIndex].scode = DISP_E_PARAMNOTFOUND;
1859 arArgs[revIndex].byref= &arRefArgs[revIndex];
1863 arArgs[revIndex].vt= varType;
1865 arArgs[revIndex].byref= & arRefArgs[revIndex].decVal;
1867 arArgs[revIndex].byref= & arRefArgs[revIndex].byref;
1873 VARTYPE
type = ::sal::static_int_cast< VARTYPE, int >( varType ^
VT_BYREF );
1876 if (
i < nUnoArgs && anyArg.getValueTypeClass() != TypeClass_VOID)
1880 else if (paramFlags & PARAMFLAG_FHASDEFAULT)
1883 VariantCopy( & arRefArgs[revIndex],
1884 & aFuncDesc->lprgelemdescParam[
i].paramdesc.
1885 pparamdescex->varDefaultValue);
1891 OSL_ASSERT(paramFlags & PARAMFLAG_FOPT);
1893 arRefArgs[revIndex].scode = DISP_E_PARAMNOTFOUND;
1899 arArgs[revIndex].vt = varType;
1900 if (revIndex == 0 && aFuncDesc->invkind == INVOKE_PROPERTYPUT)
1902 arArgs[revIndex] = arRefArgs[revIndex];
1906 arArgs[revIndex].byref= & arRefArgs[revIndex].decVal;
1910 if ( ! (paramFlags & PARAMFLAG_FOUT))
1911 arArgs[revIndex] = arRefArgs[revIndex];
1913 arArgs[revIndex].byref = & arRefArgs[revIndex];
1917 arArgs[revIndex].byref = & arRefArgs[revIndex].byref;
1918 arArgs[revIndex].vt = ::sal::static_int_cast< VARTYPE, int >( arRefArgs[revIndex].vt |
VT_BYREF );
1925 if (
i < nUnoArgs && anyArg.getValueTypeClass() != TypeClass_VOID)
1931 else if (paramFlags & PARAMFLAG_FHASDEFAULT)
1934 VariantCopy( & arArgs[revIndex],
1935 & aFuncDesc->lprgelemdescParam[
i].paramdesc.
1936 pparamdescex->varDefaultValue);
1938 else if (paramFlags & PARAMFLAG_FOPT)
1941 arArgs[revIndex].scode = DISP_E_PARAMNOTFOUND;
1946 arArgs[revIndex].lVal = 0;
1951 catch (IllegalArgumentException & e)
1953 e.ArgumentPosition = ::sal::static_int_cast< sal_Int16, sal_Int32 >(
i );
1956 catch (CannotConvertException & e)
1958 e.ArgumentIndex =
i;
1961 dispparams.rgvarg= arArgs;
1965 LOCALE_USER_DEFAULT,
1966 ::sal::static_int_cast< WORD, INVOKEKIND >( aFuncDesc->invkind ),
1977 int outParamsCount= 0;
1978 for (
int j = 0; j < aFuncDesc->cParams; j++)
1980 if (aFuncDesc->lprgelemdescParam[j].paramdesc.wParamFlags &
1985 OutParamIndex.realloc(outParamsCount);
1986 OutParam.realloc(outParamsCount);
1990 auto pOutParamIndex = OutParamIndex.getArray();
1991 auto pOutParam = OutParam.getArray();
1992 int outParamIndex=0;
1993 for (
int paramIndex = 0; paramIndex < nUnoArgs; paramIndex ++)
1996 int realParamIndex = paramIndex;
1997 int revParamIndex = dispparams.cArgs - paramIndex - 1;
1998 if (Params[paramIndex].getValueType()
2003 realParamIndex = dispparams.rgdispidNamedArgs[revParamIndex];
2007 if (! (aFuncDesc->lprgelemdescParam[realParamIndex].paramdesc.wParamFlags
2016 variantToAny( & arRefArgs[revParamIndex], outAny,
false );
2018 catch (IllegalArgumentException & e)
2020 e.ArgumentPosition =
static_cast<sal_Int16
>(paramIndex);
2023 catch (CannotConvertException & e)
2025 e.ArgumentIndex = paramIndex;
2028 pOutParam[outParamIndex] = outAny;
2029 pOutParamIndex[outParamIndex] = ::sal::static_int_cast< sal_Int16, int >( paramIndex );
2032 OutParam.realloc(outParamIndex);
2033 OutParamIndex.realloc(outParamIndex);
2045 case DISP_E_BADPARAMCOUNT:
2046 throw IllegalArgumentException(
"[automation bridge] Wrong "
2047 "number of arguments. Object returned DISP_E_BADPARAMCOUNT.",
2050 case DISP_E_BADVARTYPE:
2052 "arguments have the wrong type. Object returned "
2053 "DISP_E_BADVARTYPE.",
nullptr);
2055 case DISP_E_EXCEPTION:
2056 message = OUString::Concat(
"[automation bridge]: ")
2057 + std::u16string_view(o3tl::toU(excepinfo.bstrDescription),
2058 ::SysStringLen(excepinfo.bstrDescription));
2062 case DISP_E_MEMBERNOTFOUND:
2063 message =
"[automation bridge]: A function with the name \""
2064 + sFuncName +
"\" is not supported. Object returned "
2065 "DISP_E_MEMBERNOTFOUND.";
2066 throw IllegalArgumentException(message,
nullptr, 0);
2068 case DISP_E_NONAMEDARGS:
2069 throw IllegalArgumentException(
"[automation bridge] Object "
2070 "returned DISP_E_NONAMEDARGS",
nullptr, ::sal::static_int_cast< sal_Int16, unsigned int >( uArgErr ));
2072 case DISP_E_OVERFLOW:
2073 throw CannotConvertException(
"[automation bridge] Call failed.",
2075 static_cast<XWeak*
>(
this)), TypeClass_UNKNOWN, FailReason::OUT_OF_RANGE, uArgErr);
2077 case DISP_E_PARAMNOTFOUND:
2078 throw IllegalArgumentException(
"[automation bridge]Call failed."
2079 "Object returned DISP_E_PARAMNOTFOUND.",
2080 nullptr, ::sal::static_int_cast< sal_Int16, unsigned int >( uArgErr ));
2082 case DISP_E_TYPEMISMATCH:
2083 throw CannotConvertException(
"[automation bridge] Call failed. "
2084 "Object returned DISP_E_TYPEMISMATCH",
2086 static_cast<XWeak*
>(
this)) , TypeClass_UNKNOWN, FailReason::UNKNOWN, uArgErr);
2088 case DISP_E_UNKNOWNINTERFACE:
2090 "Object returned DISP_E_UNKNOWNINTERFACE.",
nullptr);
2092 case DISP_E_UNKNOWNLCID:
2094 "Object returned DISP_E_UNKNOWNLCID.",
nullptr);
2096 case DISP_E_PARAMNOTOPTIONAL:
2097 throw CannotConvertException(
"[automation bridge] Call failed."
2098 "Object returned DISP_E_PARAMNOTOPTIONAL",
2099 static_cast<XInterface*
>(
static_cast<XWeak*
>(
this)),
2100 TypeClass_UNKNOWN, FailReason::NO_DEFAULT_AVAILABLE, uArgErr);
2112 FUNCDESC** pFuncDesc)
2114 int nUnoArgs = seqArgs.getLength();
2115 const Any * arArgs = seqArgs.getConstArray();
2131 getPropDesc(sFuncName, & aDescGet, & aDescPut, & aVarDesc);
2134 throw IllegalArgumentException(
2135 "[automation bridge] The object does not have a writeable property: "
2138 *pFuncDesc = aDescPut.
Detach();
2151 getPropDesc(sFuncName, & aFuncDesc, & aDescPut, & aVarDesc);
2154 throw IllegalArgumentException(
2155 "[automation bridge] The object does not have a function"
2156 " or readable property \""
2160 *pFuncDesc = aFuncDesc.
Detach();
2166 LPOLESTR lpsz =
const_cast<LPOLESTR
> (o3tl::toW(sFuncName.getStr()));
2167 HRESULT
hr =
m_spDispatch->GetIDsOfNames(IID_NULL, &lpsz, 1, LOCALE_USER_DEFAULT,
id);
2173 OSL_ASSERT( * pFuncDesc ==
nullptr);
2175 typedef TLBFuncIndexMap::const_iterator cit;
2185 CComBSTR memberName;
2186 unsigned int pcNames=0;
2188 if( SUCCEEDED(
getTypeInfo()->GetNames(
id, & memberName, 1, &pcNames)))
2193 OUString sRealName(o3tl::toU(LPCOLESTR(memberName)));
2199 std::pair<cit, cit> pItems =
m_mapComFunc.equal_range( sRealName );
2200 for ( ;pItems.first != pItems.second; ++pItems.first )
2201 m_mapComFunc.insert( TLBFuncIndexMap::value_type ( std::make_pair(sFuncName, pItems.first->second ) ));
2208#if OSL_DEBUG_LEVEL >= 1
2211 std::pair<cit, cit>
p =
m_mapComFunc.equal_range(sFuncName.toAsciiLowerCase());
2213 for ( ;
p.first !=
p.second;
p.first ++, numEntries ++);
2214 OSL_ASSERT( ! (numEntries > 3) );
2219 FUNCDESC * pDesc =
nullptr;
2220 if (!SUCCEEDED(pType->GetFuncDesc(itIndex->second, & pDesc)))
2223 "FUNCDESC for " + sFuncName);
2225 if (pDesc->invkind == INVOKE_FUNC)
2227 (*pFuncDesc) = pDesc;
2231 pType->ReleaseFuncDesc(pDesc);
2238 FUNCDESC** pFuncDescPut, VARDESC** pVarDesc)
2240 OSL_ASSERT( * pFuncDescGet ==
nullptr && * pFuncDescPut ==
nullptr);
2242 typedef TLBFuncIndexMap::const_iterator cit;
2243 std::pair<cit, cit>
p =
m_mapComFunc.equal_range(sFuncName);
2250 CComBSTR memberName;
2251 unsigned int pcNames=0;
2253 if( SUCCEEDED(
getTypeInfo()->GetNames(
id, & memberName, 1, &pcNames)))
2258 p =
m_mapComFunc.equal_range(OUString(o3tl::toU(LPCOLESTR(memberName))));
2263 for (
int i = 0 ;
p.first !=
p.second;
p.first ++,
i ++)
2266 OSL_ASSERT( ! (
i > 2) );
2268 FUNCDESC * pFuncDesc =
nullptr;
2269 if (SUCCEEDED( pType->GetFuncDesc(
p.first->second, & pFuncDesc)))
2271 if (pFuncDesc->invkind == INVOKE_PROPERTYGET)
2273 (*pFuncDescGet) = pFuncDesc;
2275 else if (pFuncDesc->invkind == INVOKE_PROPERTYPUT ||
2276 pFuncDesc->invkind == INVOKE_PROPERTYPUTREF)
2281 if ( * pFuncDescPut)
2284 pType->ReleaseFuncDesc(pFuncDesc);
2288 (*pFuncDescPut) = pFuncDesc;
2293 pType->ReleaseFuncDesc(pFuncDesc);
2300 VARDESC * pVD =
nullptr;
2301 if (SUCCEEDED(pType->GetVarDesc(
p.first->second, & pVD)))
2312 CComPtr<ITypeInfo> spRefInfo;
2313 pTypeInfo->GetRefTypeInfo( nHrefType, &spRefInfo.p );
2317 spRefInfo->GetTypeAttr( &attr );
2318 if ( attr->typekind == TKIND_ENUM )
2321 if ( attr->cVars == 0 )
2326 spRefInfo->GetVarDesc( 0, &var );
2327 _type = var->lpvarValue->vt;
2329 else if ( attr->typekind == TKIND_INTERFACE )
2333 else if ( attr->typekind == TKIND_DISPATCH )
2335 _type = VT_DISPATCH;
2337 else if ( attr->typekind == TKIND_ALIAS )
2355 if (desc->vt == VT_PTR)
2360 else if (desc->vt == VT_SAFEARRAY)
2365 else if (desc->vt == VT_USERDEFINED)
2388 if( SUCCEEDED( pType->GetTypeAttr( &typeAttr)))
2390 for(
WORD i= 0;
i < typeAttr->cFuncs;
i++)
2393 if( SUCCEEDED( pType->GetFuncDesc(
i, &funcDesc)))
2395 CComBSTR memberName;
2396 unsigned int pcNames=0;
2397 if( SUCCEEDED(pType->GetNames( funcDesc->memid, & memberName, 1, &pcNames)))
2399 OUString usName(o3tl::toU(LPCOLESTR(memberName)));
2404 sError =
"[automation bridge] IUnknownWrapper::buildComTlbIndex, "
2405 "ITypeInfo::GetNames failed.";
2409 sError =
"[automation bridge] IUnknownWrapper::buildComTlbIndex, "
2410 "ITypeInfo::GetFuncDesc failed.";
2415 for (
WORD i = 0;
i < typeAttr->cVars;
i++)
2418 if (SUCCEEDED(pType->GetVarDesc(
i, & varDesc)))
2420 CComBSTR memberName;
2421 unsigned int pcNames = 0;
2422 if (SUCCEEDED(pType->GetNames(varDesc->memid, & memberName, 1, &pcNames)))
2424 if (varDesc->varkind == VAR_DISPATCH)
2426 OUString usName(o3tl::toU(LPCOLESTR(memberName)));
2432 sError =
"[automation bridge] IUnknownWrapper::buildComTlbIndex, "
2433 "ITypeInfo::GetNames failed.";
2437 sError =
"[automation bridge] IUnknownWrapper::buildComTlbIndex, "
2438 "ITypeInfo::GetVarDesc failed.";
2443 sError =
"[automation bridge] IUnknownWrapper::buildComTlbIndex, "
2444 "ITypeInfo::GetTypeAttr failed.";
2446 if (sError.getLength())
2469 CComPtr< ITypeInfo > spType;
2470 if( !SUCCEEDED(
m_spDispatch->GetTypeInfo( 0, LOCALE_USER_DEFAULT, &spType.p)))
2473 "support ITypeInfo!");
2476 OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
2481 if( SUCCEEDED(spType->GetTypeAttr( &typeAttr)))
2483 if (typeAttr->typekind == TKIND_INTERFACE &&
2484 typeAttr->wTypeFlags & TYPEFLAG_FDUAL)
2486 HREFTYPE refDispatch;
2487 if (!SUCCEEDED(spType->GetRefTypeOfImplType(::sal::static_int_cast< UINT, int >( -1 ), &refDispatch)))
2490 "[automation bridge] Could not obtain type information "
2491 "for dispatch interface." );
2493 CComPtr<ITypeInfo> spTypeDisp;
2494 if (SUCCEEDED(spType->GetRefTypeInfo(refDispatch, & spTypeDisp)))
2497 else if (typeAttr->typekind == TKIND_DISPATCH)
2504 "[automation bridge] Automation object does not "
2505 "provide type information.");
~IUnknownWrapper() override
virtual css::uno::Any SAL_CALL directInvoke(const OUString &aName, const css::uno::Sequence< css::uno::Any > &aParams) override
virtual Reference< XInterface > createUnoWrapperInstance() override
OUString m_sDefaultMember
TypeDescription getInterfaceMemberDescOfCurrentCall(std::u16string_view sName)
bool m_bOriginalDispatch
This value is set during XInitialization::initialize.
virtual Reference< XInterface > createComWrapperInstance() override
Any SAL_CALL queryInterface(const Type &t) override
IUnknownWrapper(Reference< XMultiServiceFactory > const &xFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass)
ITypeInfo * getTypeInfo()
Returns always a valid ITypeInfo interface or throws a BridgeRuntimeError.
virtual Any invokeWithDispIdUnoTlb(const OUString &sFunctionName, const Sequence< Any > &Params, Sequence< sal_Int16 > &OutParamIndex, Sequence< Any > &OutParam)
virtual sal_Bool SAL_CALL hasProperty(const OUString &aName) override
virtual css::uno::Any SAL_CALL invokePutProperty(const OUString &aFunctionName, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Sequence< ::sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam) override
virtual void SAL_CALL initialize(const Sequence< Any > &aArguments) override
VARTYPE getUserDefinedElementType(ITypeInfo *pTypeInfo, const DWORD nHrefType)
virtual sal_Bool SAL_CALL hasMember(const OUString &aName) override
void buildComTlbIndex()
Iterates over all functions and put the names and indices into the map m_mapComFunc of type TLBFuncIn...
virtual void SAL_CALL setValue(const OUString &aPropertyName, const Any &aValue) override
void getMethodInfo(std::u16string_view sName, TypeDescription &methodDescription)
bool getDispid(const OUString &sFuncName, DISPID *id)
Returns the DISPID for a function or property name.
CComPtr< IDispatch > m_spDispatch
void getFuncDescForInvoke(const OUString &sFuncName, const Sequence< Any > &seqArgs, FUNCDESC **pFuncDesc)
Returns a FUNCDESC structure which contains type information about the current XInvocation::invoke ca...
Sequence< Type > m_seqTypes
VARTYPE getElementTypeDesc(const TYPEDESC *desc)
Gets the element type in a VARIANT like style.
virtual sal_Bool SAL_CALL hasMethod(const OUString &aName) override
void getPropDesc(const OUString &sFuncName, FUNCDESC **pFuncDescGet, FUNCDESC **pFuncDescPut, VARDESC **pVarDesc)
Obtains a FUNCDESC structures or a VARDESC structure for a property.
virtual Reference< XIntrospectionAccess > SAL_CALL getIntrospection() override
virtual Any SAL_CALL createBridge(const Any &modelDepObject, const Sequence< sal_Int8 > &aProcessId, sal_Int16 sourceModelType, sal_Int16 destModelType) override
void getAttributeInfo(std::u16string_view sName, TypeDescription &attributeInfo)
Any invokeWithDispIdComTlb(FuncDesc &aFuncDesc, const OUString &sFuncName, const Sequence< Any > &Params, Sequence< sal_Int16 > &OutParamIndex, Sequence< Any > &OutParam)
TLBFuncIndexMap m_mapComFunc
virtual Any SAL_CALL invoke(const OUString &aFunctionName, const Sequence< Any > &aParams, Sequence< sal_Int16 > &aOutParamIndex, Sequence< Any > &aOutParam) override
virtual css::uno::Any SAL_CALL invokeGetProperty(const OUString &aFunctionName, const css::uno::Sequence< css::uno::Any > &aParams, css::uno::Sequence< ::sal_Int16 > &aOutParamIndex, css::uno::Sequence< css::uno::Any > &aOutParam) override
CComPtr< ITypeInfo > m_spTypeInfo
virtual Any SAL_CALL getValue(const OUString &aPropertyName) override
void getFuncDesc(const OUString &sFuncName, FUNCDESC **pFuncDesc)
Obtains a FUNCDESC structure for a function.
JScriptDetermination m_eJScript
CComPtr< IUnknown > m_spUnknown
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
const sal_uInt8 m_nComWrapperClass
css::uno::Type const & get()
Reference< XSingleServiceFactory > xFactory
Sequence< PropertyValue > aArguments
#define SAL_WARN(area, stream)
MetadataImporterPluginType * result
struct _typelib_TypeDescription typelib_TypeDescription
Any SAL_CALL getCaughtException()
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void o2u_attachCurrentThread()
std::unordered_map< sal_uIntPtr, sal_uIntPtr > WrapperToAdapterMap
std::unordered_map< sal_uIntPtr, WeakReference< XInterface > > ComPtrToWrapperMap
std::unordered_map< sal_uIntPtr, sal_uIntPtr > AdapterToWrapperMap
#define JSCRIPT_ID_PROPERTY
#define UNO_OBJECT_WRAPPER_REMOTE_OPT
#define INTERFACE_OLE_WRAPPER_IMPL