sharing ADXExcelAddinModule and ADXAddinModule

Add-in Express™ Support Service
That's what is more important than anything else

sharing ADXExcelAddinModule and ADXAddinModule
 
Andrew Westacott




Posts: 5
Joined: 2006-10-12
Hi,

I have an addin derived from ADXAddinModule that implements some toolbars etc and uses a singleton class in a thirdparty libary to connect to a server. I also have a ADXExcelAddinModule derived class that implements some excel methods that also need to call in same thirdparty singleton. The problem is that it looks like the function and addin get loaded seperatly some they cannot share the same singletons state. Is this the case and if so how can I get around it?

Regards
Andy
Posted 12 Oct, 2006 09:03:41 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Hi Andy.

Yes, correct. The fact is that COM add-ins and Excel Automation add-ins are different technologies and the modules are loaded separately. Therefore you can't have the global data within one assembly. However you can use the Marshal.GetActiveObject method to obtain the current instance of Excel application to access the add-in via the COM Add-ins collection of the application object.
Posted 12 Oct, 2006 11:58:04 Top
Andrew Westacott




Posts: 5
Joined: 2006-10-12
Thanks,

Ok so either automation add-in or the com add-in would be the owner of the thirdparty singleton and the other add-in would have to call into the first add-in using the GetActiveObject and perform com calls on the returned object to access the singleton. correct?

I don't suppose you have any samples like this do you?

Regards
Andy
Posted 12 Oct, 2006 12:19:39 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Yes, correct. I have an example with the RTD server and a COM add-in in one assembly. You can download it and use the same code to access the add-in from the ExcelAddinModule class:
http://www.add-in-express.com/projects/rtdandaddin.zip
Posted 12 Oct, 2006 16:37:28 Top
Andrew Westacott




Posts: 5
Joined: 2006-10-12
I tried and it works as expected but when I lift the code and put into my project so that the ADXExcelAddinModule calls GetModule to access the AddIn I get a null returned. Looking into it some more an addin.Object for my addin does exist but is of type System.Runtime.Remoting.Proxies.__TransparentProxy.

Any ideas?
Posted 13 Oct, 2006 04:26:00 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Hi Andrew.

Do you use the adxloader.dll or C++ shim?
Posted 13 Oct, 2006 09:43:00 Top
Andrew Westacott




Posts: 5
Joined: 2006-10-12
Hi,

I am using the adxloader.dll
Posted 13 Oct, 2006 09:44:12 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
In this case you need to use the CallProxyMethod, GetProxyProperty and SetProxyProperty methods to make calls from the Excel module to the addinmodule loaded in a separate app domain. Please look at the OutlookPropertyPage example from the ADX installation package to learn how you can use the ADX proxy methods.
Posted 13 Oct, 2006 11:25:39 Top
Andrew Westacott




Posts: 5
Joined: 2006-10-12
ok. That seems to work fine for me. Just one question. It's ok if I call a method across the add-in boundaries that in turn calls a method on the singleton. What if I want to return the singleton in the method so the other add-in can methods directly? At the moment this doesn't work.
Posted 16 Oct, 2006 05:01:18 Top
Sergey Grischenko


Add-in Express team


Posts: 7230
Joined: 2004-07-05
Hi Andrew.

If you return the singleton in the proxy method, you will get the proxy wrapper. However you can inherit the singleton from the MarshalByRefObject class and then you will able to cast the proxy object to the type of the singleton class.
Posted 16 Oct, 2006 11:49:42 Top