Hi,
Your host is not quite right.
You need to store the RegisterId when you load the other add-in, and
use that in the unregister calls.
So you have two unregister calls:
1. To unregister the xlAutoRemove function
2. To unregister the loaded add-in after you've called xlAutoRemove.
Try the version below (also at
https://gist.github.com/1200178).
-Govert
<DnaLibrary Name="AddInHost" Language="C#" RuntimeVersion="v4.0">
<Reference Name="System.Windows.Forms" />
<![CDATA[
using System;
using System.Windows.Forms;
using ExcelDna.Integration;
public class MyMacros
{
public static object registerId;
[ExcelCommand(MenuName="AddinHost", MenuText="Load Addin")]
public static void LoadAddin()
{
XlCall.XlReturn result = XlCall.TryExcel(XlCall.xlfRegister,
out registerId, @"C:\Work\ExcelDna\Samples\MetaAddin\AddIn.xll");
}
[ExcelCommand(MenuName="AddinHost", MenuText="Unload Addin")]
public static void UnloadAddin()
{
MessageBox.Show("About to call xlAutoRemove.");
string theName = @"C:\Work\ExcelDna\Samples\MetaAddin
\AddIn.xll";
object removeId = XlCall.Excel(XlCall.xlfRegister, theName,
"xlAutoRemove", "I" , ExcelMissing.Value, ExcelMissing.Value, 2);
object removeResult = XlCall.Excel(XlCall.xlfCall, removeId);
object removeUnregister = XlCall.Excel(XlCall.xlfUnregister,
removeId);
object success = XlCall.Excel(XlCall.xlfUnregister,
registerId);
MessageBox.Show("Result of Unregister: " +
success.ToString() );
}
}
public static class MyFunctions
{
public static string AddinHostTestFunction()
{
return "Hello from the add-in host!";
}
[ExcelCommand(MenuName="AddinHost", MenuText="Say Hello!")]
public static void AddIn()
{
MessageBox.Show("Hello from the add-in host!");
}
}
]]>
</DnaLibrary>