|  | 
| 14 | 14 | using System.Runtime.InteropServices; | 
| 15 | 15 | using System.Windows.Forms; | 
| 16 | 16 | using System.Windows.Threading; | 
|  | 17 | +using Microsoft.Vbe.Interop; | 
| 17 | 18 | using Ninject.Extensions.Interception; | 
| 18 | 19 | using NLog; | 
| 19 | 20 | using Rubberduck.Settings; | 
| 20 | 21 | using Rubberduck.SettingsProvider; | 
| 21 | 22 | using Rubberduck.VBEditor.Events; | 
|  | 23 | +using Rubberduck.VBEditor.SafeComWrappers; | 
| 22 | 24 | using Rubberduck.VBEditor.SafeComWrappers.Abstract; | 
| 23 | 25 | 
 | 
| 24 | 26 | namespace Rubberduck | 
| @@ -52,13 +54,13 @@ public void OnConnection(object Application, ext_ConnectMode ConnectMode, object | 
| 52 | 54 |         { | 
| 53 | 55 |             try | 
| 54 | 56 |             { | 
| 55 |  | -                if (Application is Microsoft.Vbe.Interop.VBE) | 
|  | 57 | +                if (Application is VBE) | 
| 56 | 58 |                 { | 
| 57 |  | -                    var vbe = (Microsoft.Vbe.Interop.VBE) Application;                   | 
|  | 59 | +                    var vbe = (VBE) Application;                   | 
| 58 | 60 |                     _ide = new VBEditor.SafeComWrappers.VBA.VBE(vbe); | 
| 59 | 61 |                     VBENativeServices.HookEvents(_ide); | 
| 60 | 62 | 
 | 
| 61 |  | -                    var addin = (Microsoft.Vbe.Interop.AddIn)AddInInst; | 
|  | 63 | +                    var addin = (AddIn)AddInInst; | 
| 62 | 64 |                     _addin = new VBEditor.SafeComWrappers.VBA.AddIn(addin) { Object = this }; | 
| 63 | 65 |                 } | 
| 64 | 66 |                 else if (Application is Microsoft.VB6.Interop.VBIDE.VBE) | 
| @@ -221,35 +223,31 @@ private void Startup() | 
| 221 | 223 | 
 | 
| 222 | 224 |         private void ShutdownAddIn() | 
| 223 | 225 |         { | 
|  | 226 | +            Debug.WriteLine("Extension unhooking VBENativeServices events."); | 
| 224 | 227 |             VBENativeServices.UnhookEvents(); | 
| 225 | 228 | 
 | 
| 226 | 229 |             var currentDomain = AppDomain.CurrentDomain; | 
| 227 | 230 |             currentDomain.AssemblyResolve -= LoadFromSameFolder; | 
| 228 |  | - | 
|  | 231 | +            Debug.WriteLine("Extension broadcasting shutdown."); | 
| 229 | 232 |             User32.EnumChildWindows(_ide.MainWindow.Handle(), EnumCallback, new IntPtr(0)); | 
| 230 | 233 | 
 | 
|  | 234 | +            Debug.WriteLine("Extension calling ReleaseDockableHosts."); | 
|  | 235 | +            VBEditor.SafeComWrappers.VBA.Windows.ReleaseDockableHosts(); | 
|  | 236 | + | 
| 231 | 237 |             if (_app != null) | 
| 232 | 238 |             { | 
|  | 239 | +                Debug.WriteLine("Extension calling App.Shutdown."); | 
| 233 | 240 |                 _app.Shutdown(); | 
| 234 | 241 |                 _app = null; | 
| 235 | 242 |             } | 
| 236 | 243 | 
 | 
| 237 | 244 |             if (_kernel != null) | 
| 238 | 245 |             { | 
|  | 246 | +                Debug.WriteLine("Extension calling Kernel.Dispose."); | 
| 239 | 247 |                 _kernel.Dispose(); | 
| 240 | 248 |                 _kernel = null; | 
| 241 | 249 |             } | 
| 242 | 250 | 
 | 
| 243 |  | -            //try | 
| 244 |  | -            //{ | 
| 245 |  | -            //    _ide.Release(); | 
| 246 |  | -            //} | 
| 247 |  | -            //catch (Exception e) | 
| 248 |  | -            //{ | 
| 249 |  | -            //    _logger.Error(e); | 
| 250 |  | -            //} | 
| 251 |  | - | 
| 252 |  | -            GC.WaitForPendingFinalizers(); | 
| 253 | 251 |             _isInitialized = false; | 
| 254 | 252 |         } | 
| 255 | 253 | 
 | 
|  | 
0 commit comments