Is there a-share data between a VSTO add in and an Excel DNA add in? Or can the Excel DNA add in is loaded into the VSTO ' s app domain?
The Excel-dna add-in is always is in a separate AppDomain. You might a try to pass an object via the AddIn's object property. Any Marshalbyref object works across AppDomains, but you need make the initial link ...
Finally I ended up with this approach:
1) Put the Sharable objects in a class lib and mark them COM visible:
namespacesharedlib{usingSystem.Runtime.InteropServices; [ComVisible (true)] [InterfaceType (cominterfacetype.interfaceisdual)] Public InterfaceIsharedobject {intGetvstoinstancenumber (); } [ComVisible (true)] [ClassInterface (ClassInterfaceType.None)] Public classSharedobject:isharedobject {Private ReadOnly intseed; Private intserial; PublicSharedobject (intseed) { This. Seed =seed; } Public intGetvstoinstancenumber () {return++serial + This. Seed; } }}
2) in VSTO create an instance of the shareable object and expose it via Requestcomaddinautomationservice:
namespacesampleexceladdin{usingSharedlib; Public Partial classThisAddIn {Private Const intSeed =Ten; PrivateIsharedobject Sharedobject; protected Override ObjectRequestcomaddinautomationservice () {if(Sharedobject = =NULL) {Sharedobject=NewSharedobject (Seed); } returnSharedobject; } ... code removed forbrevity ...}}
3) Now consume the shared object in the Excel DNA class Lib:
namespaceexcelfunctions{usingexceldna.integration; usingExcel =Microsoft.Office.Interop.Excel; usingSharedlib; Public classexcelfunctions {[Excelfunction (Description="Gets A serial number from the VSTO")] Public Static intGetvstoinstancenumber () {varApplication =(Excel.Application) exceldnautil.application; ObjectAddinname ="Sampleexceladdin"; varAddIn = Application.COMAddIns.Item (refaddinname); varUtils =(isharedobject) addin. Object; returnUtils. Getvstoinstancenumber (); } }}
Share data between VSTO and Excel DNA App domains