ADXXLLModule.CurrentInstance is not null even if XLL Add-In not Opened and not installed.

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

ADXXLLModule.CurrentInstance is not null even if XLL Add-In not Opened and not installed.
How can I check if the UDF provided by the XLL module are available 
Dirk




Posts: 73
Joined: 2017-10-05
Hello,

we have an XLL Module that is registered by adxregistrator. If I deactivate it in the Excel Add-In Manager, the ADXXLLModule.CurrentInstance is not Null. I would expected that a Null check can be used to detect if the Xll Module is active. After deactivating the XLL Module the UDF are not available.
How can I check if the xll module is providing its UDFs?


best regards,
Dirk
Posted 02 Apr, 2019 02:57:01 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello dirk,

In my case, if I turn my XLL add-in off, XllModule1.CurrentInstance (called from a COM add-in module) returns null:

private void adxRibbonButton2_OnClick(object sender, IRibbonControl control, bool pressed)
{
    object obj = XLLModule1.CurrentInstance;
    MessageBox.Show(obj == null ? "null" : "not null");
}


My steps are as follows:
- install my assembly and register a COM add-in plus an XLL add-in
- start Excel
- in the COM add-in, click the Ribbon button above; this produces "not null" as expected
- in the Add-ins dialog, turn off the XLL add-in
- in the COM add-in, click the Ribbon button above; this produces "null"


Andrei Smolin
Add-in Express Team Leader
Posted 02 Apr, 2019 04:38:19 Top
Dirk




Posts: 73
Joined: 2017-10-05
Ok.Thanks.

I double checked:
1) The entry Software\Microsoft\office\16.0\Excel\Options\OPEN is not there
2) The XLL constructor is running and current instance is set
3) The UDF are not available
4) we use 9.2.4635.0 of AddInExpress\AddinExpress.MSO.2005.dll
5) The Excel Add-In Dialog shows, that the addin is there but it is not checked and therefor not loaded.
6) I added a breakpoint in the ctor of the XLL Module:
We enumerate all Excel Add-In foreach(Excel.AddIn addIn in ExcelApp.AddIns) and excel seems to load the add-in in this moment. If I remove this code, the ctor XLL Modul is not executed.

Do you know the reason why excel create a instance of the Execl Add-in if we enumerate through the Addins collection?
Posted 02 Apr, 2019 06:50:18 Top
Dirk




Posts: 73
Joined: 2017-10-05
Because we cannot prevent an other application (macro, add-in) to iterate through the add-in collection, we cannot make sure the test for ADXXLLModule.CurrentInstance == null gives us the reliable answer for the question: "Is the Xll Modul active and the UDF are registered?"
Do you have any idea what we can use to check?
Posted 02 Apr, 2019 06:55:15 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Dirk Reu? writes:
I double checked:


How can I reproduce this? Note that I've registered a COM add-in *plus an XLL add-in*; this means the OPEN registry value was created and this is why Excel loads the add-in at startup.

Dirk Reu? writes:
We enumerate all Excel Add-In foreach(Excel.AddIn addIn in ExcelApp.AddIns) and excel seems to load the add-in in this moment.


I assume you also call addIn.{some property or method here} in that loop. If so, to let you call that member, Excel must load the DLL providing an instance of the class providing that member.

I suppose you can declare a public property in your COM add-in that the XLL module can set as required in the Initialize and Finalize events (our guys say Excel can load and then unload your XLL add-in if it isn't required).


Andrei Smolin
Add-in Express Team Leader
Posted 02 Apr, 2019 07:11:28 Top
Dirk




Posts: 73
Joined: 2017-10-05
I've register a COM and XLL Add-In, too.
The COM-Add-In checks in OnHostApplicationInitialized and later if the XLLModule.CurrentInstance != null.
Yes the OPEN= /R "<pathtoaddin.dll>" is removed by excel if I deactivate the excel add-in (you have to restart excel)
The xll add-in ctor is call if you add this code in the OnHostApplicationInitialized() in the COM Add-in:

foreach (Excel.AddIn addIn in ExcelApp.AddIns)
{

}

We use Name and Installed property on the addIn object. But it is loaded exactly while accessing ExcelApp.AddIns collection. The simple loop above with any property access creates the instance of the xll add-in.
Posted 02 Apr, 2019 07:28:20 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Dirk,

I assume this can be explained by the inner logic of Excel. Probably, you can check the registry instead.

Dirk Reu? writes:
Yes the OPEN= /R "<pathtoaddin.dll>" is removed by excel


In this case, your add-in is listed under HKEY_CURRENT_USER\Software\Microsoft\Office\{version}.0\Excel\Add-in Manager.

The sample project accompanying https://www.add-in-express.com/creating-addins-blog/2010/03/24/addin-xll-rtd-one-assembly/ post on our web site demonstrates using a class instance (MyCommonData.cs) as the data store for the COM add-in and XLL add-in. Specifically, that class checks the CurrentInstance property on the add-in module, XLL module, and RTD server module. You can rewrite that class so that the constructor of every module adds the module to that class. In this way, you can find out if a given module was created (loaded).


Andrei Smolin
Add-in Express Team Leader
Posted 02 Apr, 2019 08:22:30 Top