| @@ -69,17 +69,26 @@ public: | |||
| String getStringFromDISPID (const DISPID hash) const | |||
| { | |||
| for (int i = identifierPool.size(); --i >= 0;) | |||
| if (getHashFromString (identifierPool[i]) == hash) | |||
| return identifierPool[i]; | |||
| return identifierNames [identifierIDs.indexOf (hash)]; | |||
| } | |||
| return String::empty; | |||
| DISPID getDISPIDForName (const String& name) | |||
| { | |||
| const int i = identifierNames.indexOf (String (name)); | |||
| if (i >= 0) | |||
| return identifierIDs[i]; | |||
| const DISPID newID = (DISPID) name.hashCode64(); | |||
| identifierNames.add (name); | |||
| identifierIDs.add (newID); | |||
| return newID; | |||
| } | |||
| HRESULT doGetIDsOfNames (LPOLESTR* rgszNames, UINT cNames, DISPID* rgDispId) | |||
| { | |||
| for (unsigned int i = 0; i < cNames; ++i) | |||
| rgDispId[i] = getHashFromString (identifierPool.getPooledString (String (rgszNames[i]))); | |||
| rgDispId[i] = getDISPIDForName (rgszNames[i]); | |||
| return S_OK; | |||
| } | |||
| @@ -97,36 +106,33 @@ public: | |||
| if ((wFlags & DISPATCH_METHOD) != 0) | |||
| { | |||
| if (! object->hasMethod (memberId)) | |||
| return DISP_E_MEMBERNOTFOUND; | |||
| const int numArgs = pDispParams == nullptr ? 0 : pDispParams->cArgs; | |||
| var result; | |||
| if (numArgs == 0) | |||
| { | |||
| result = v.call (memberId); | |||
| } | |||
| else | |||
| if (object->hasMethod (memberId)) | |||
| { | |||
| Array<var> args; | |||
| for (int j = numArgs; --j >= 0;) | |||
| args.add (variantTojuceVar (pDispParams->rgvarg[j])); | |||
| const int numArgs = pDispParams == nullptr ? 0 : pDispParams->cArgs; | |||
| var result; | |||
| result = v.invoke (memberId, numArgs == 0 ? 0 : args.getRawDataPointer(), numArgs); | |||
| } | |||
| if (numArgs == 0) | |||
| { | |||
| result = v.call (memberId); | |||
| } | |||
| else | |||
| { | |||
| Array<var> args; | |||
| for (int j = numArgs; --j >= 0;) | |||
| args.add (variantTojuceVar (pDispParams->rgvarg[j])); | |||
| if (pVarResult != nullptr) | |||
| juceVarToVariant (result, *pVarResult); | |||
| result = v.invoke (memberId, numArgs == 0 ? nullptr : args.getRawDataPointer(), numArgs); | |||
| } | |||
| return S_OK; | |||
| if (pVarResult != nullptr) | |||
| juceVarToVariant (result, *pVarResult); | |||
| return S_OK; | |||
| } | |||
| } | |||
| else if ((wFlags & DISPATCH_PROPERTYGET) != 0) | |||
| { | |||
| if (! object->hasProperty (memberId)) | |||
| return DISP_E_MEMBERNOTFOUND; | |||
| if (pVarResult != nullptr) | |||
| if (object->hasProperty (memberId) && pVarResult != nullptr) | |||
| { | |||
| juceVarToVariant (object->getProperty (memberId), *pVarResult); | |||
| return S_OK; | |||
| @@ -145,12 +151,8 @@ public: | |||
| } | |||
| private: | |||
| StringPool identifierPool; | |||
| static DISPID getHashFromString (const String::CharPointerType s) noexcept | |||
| { | |||
| return (DISPID) (pointer_sized_int) s.getAddress(); | |||
| } | |||
| Array<DISPID> identifierIDs; | |||
| StringArray identifierNames; | |||
| JUCE_DECLARE_NON_COPYABLE (IDispatchHelper) | |||
| }; | |||