ShokoAnime / MyAnime3

Repository for My Anime 3, a MediaPortal plugin.
http://shokoanime.com/mediaportal/
15 stars 10 forks source link

Keyboard hook is producing messaging events on a disposed form #12

Closed jmediamanager closed 9 years ago

jmediamanager commented 10 years ago

Reported by maximo.piva@nutzcode.com, Jun 21, 2013

The form is used by Mediaportal RefreshRate system and it's called 'SuicideForm'

Step to reproduce:

  1. Enable Dynamic Refresh Rate on Media Portal 1.4.0
  2. Play 2 o 3 movies that have different refresh rate (Ex 24fps)

Looking at the keyboard hook, on the sources right now.

Jun 21, 2013 maximo.piva

Okey, found the culprit, disabled right now:

    void SubClass()
        {
            IntPtr hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            NewWindowProc = new WindowProc(MyWindowProc);
            DefWindowProc = SetWindowLongPtr(hWnd, GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(NewWindowProc));
        }

        void UnSubClass()
        {
            IntPtr hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            DefWindowProc = SetWindowLongPtr(hWnd, GWL_WNDPROC, DefWindowProc);
            DefWindowProc = IntPtr.Zero;
        }

        int MyWindowProc(System.IntPtr hWnd, int msg, int wParam, int lParam)
        {
            if (msg == WM_ACTIVATEAPP)
            {
                //disable keyboard hook if app is inactive
                // wParam=1 when activating, 0 when desactivating
                hook.IsEnabled = (wParam == 1);
            }

            return CallWindowProc(DefWindowProc, hWnd, msg, wParam, lParam);
        }

For some reasone, this SubClass. Makes or forwards the RefreshRate SucideForm Messages. The End Result, CallWndProc is probably forwarding Messages to a Disposed SucideForm.

Current Fix:

Commented Calls to SubClass end UnSubClass in the code.... Working fine...

jmediamanager commented 9 years ago

Closing issue as Maximo had already checked this into the code