INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Opposite of Init?  (Read 5563 times)

dhiggins

  • Regular Member
  • World Citizen
  • ***
  • Posts: 126
Opposite of Init?
« on: September 19, 2008, 10:50:41 pm »

Hi

Anyone know if there's any way to detect when a plugin is "unloaded." Granted, it looks like the only time that happens is during MC shutdown, but there doesn't appear to be any shutdown event.

And since I'm in VB.NET, the finalize/dispose methods don't get called in this particular case (I'm guessing because MC deals with COM objects, which are treated special in VB.NET).

The HandleDestroyed event does get fired, but it appears to get fired EVERY time I click away from the plugin screen. When I click back to it, the control appears to be recreated, so that's not accurate as to the app actually shutting down.

The reason I ask, is that it'd be nice to have some spot to attach "shutdown" behaviors, saving settings, that sort of thing.

I could do it "as the user clicks", but in some cases, that's not the greatest solution.

Logged

dhiggins

  • Regular Member
  • World Citizen
  • ***
  • Posts: 126
Re: Opposite of Init?
« Reply #1 on: September 20, 2008, 09:49:17 am »

Never mind.

I used a bit of subclassing, plus FindWindow to locate the main MC UI Window (Class of MJFrame), then subclassed it and monitor for the WM_DESTROY message.

When that comes through, I know that MC is shutting down, so I can trigger my own internal "Shutdown" event.

Works a charm, at least so far. Just hoping MC never destroys that window for any other reason, though it hasn't seemed to yet.
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Opposite of Init?
« Reply #2 on: September 20, 2008, 11:19:17 am »

That sounds quite useful.  Maybe you could put a code sample up?

muchadhesion

  • Recent member
  • *
  • Posts: 44
Re: Opposite of Init?
« Reply #3 on: January 07, 2009, 03:02:23 pm »

I'm also looking for somewhere to put my tear-down code.  (Disconnecting from servers etc...)

I'm using C# and I'm not seeing any evidence of my Dispose method being called.

I've also tried using the ParentForm.FormClosing event, but the parent form is null.

Is there a cleaner approach than watching for WM_DESTROY on the main MJFrame?

TIA

Logged

muchadhesion

  • Recent member
  • *
  • Posts: 44
Re: Opposite of Init?
« Reply #4 on: January 10, 2009, 05:52:58 am »

For what its worth here is my code for hooking into JRiver shutdown.  It's not pretty, but it seems to work. 
Would appreciate any better offers?

(WndProc Code added to the C# template)


   public partial class MainInterface : UserControl
   {
      public MainInterface()
      {
         InitializeComponent();
      }

        protected override void WndProc(ref Message m)
        {
         const int WM_DESTROY = 0x0002;
            // Listen for operating system messages.
            switch (m.Msg)
            {
            // The WM_DESTROY message occurs when the application exits
                case WM_DESTROY:
               FormClosing(null,null);  // Call plugin shutdown code
                    break;               
            }
            base.WndProc(ref m);
        }
Logged
Pages: [1]   Go Up