// NOTE: We are not currently removing the functions from the Jmp array // That would be needed to do a proper per-method deregistration, // together with a garbage-collectable story for the wrapper methods and delegates, // instead of the currently runtime-compiled and loaded assemblies. internal static void UnregisterMethods() { object xlCallResult; // Remove menus and ShortCuts IntegrationHelpers.RemoveCommandMenus(); UnregisterShortCuts(); // Now take out the methods foreach (XlMethodInfo mi in registeredMethods) { if (mi.IsCommand) { // Clear the name and unregister XlCallImpl.TryExcelImpl(XlCallImpl.xlfSetName, out xlCallResult, mi.Name); XlCallImpl.TryExcelImpl(XlCallImpl.xlfUnregister, out xlCallResult, mi.RegisterId); } else { // And Unregister the real function XlCallImpl.TryExcelImpl(XlCallImpl.xlfUnregister, out xlCallResult, mi.RegisterId); // I follow the advice from X-Cell website to get function out of Wizard (with fix from kh) XlCallImpl.TryExcelImpl(XlCallImpl.xlfRegister, out xlCallResult, XlAddIn.PathXll, "xlAutoRemove", "I", mi.Name, IntegrationMarshalHelpers.GetExcelMissingValue(), 2); if (xlCallResult is double) { double fakeRegisterId = (double)xlCallResult; XlCallImpl.TryExcelImpl(XlCallImpl.xlfSetName, out xlCallResult, mi.Name); XlCallImpl.TryExcelImpl(XlCallImpl.xlfUnregister, out xlCallResult, fakeRegisterId); } } } registeredMethods.Clear(); registrationInfo.Clear(); }
internal static void UnregisterMethods() { object xlCallResult; // Remove menus IntegrationHelpers.RemoveCommandMenus(); // Now take out the methods foreach (XlMethodInfo mi in registeredMethods) { if (mi.IsCommand) { XlCallImpl.TryExcelImpl(XlCallImpl.xlfSetName, out xlCallResult, mi.Name, ""); } else { // I follow the advice from X-Cell website // to get function out of Wizard XlCallImpl.TryExcelImpl(XlCallImpl.xlfRegister, out xlCallResult, pathXll, "xlAutoRemove", "J", mi.Name, IntegrationMarshalHelpers.GetExcelMissingValue(), 0); } XlCallImpl.TryExcelImpl(XlCallImpl.xlfUnregister, out xlCallResult, mi.RegisterId); } registeredMethods.Clear(); }