From 687ff0594886eac198829b6f37fdf6444cd9eb51 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Wed, 24 Oct 2018 21:41:29 -0500 Subject: [PATCH] Corrected unregister notify call Changed location and corrected used handle --- DS4Windows/DS4Forms/DS4Form.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index f1b6ee7..dda0fa0 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -57,6 +57,7 @@ namespace DS4Windows bool turnOffTemp; bool runningBat; private bool changingService; + private IntPtr regHandle = new IntPtr(); private static DS4Form instance; Dictionary hoverTextDict = new Dictionary(); // 0 index is used for application version text. 1 - 4 indices are used for controller status @@ -1049,8 +1050,7 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question { Guid hidGuid = new Guid(); NativeMethods.HidD_GetHidGuid(ref hidGuid); - IntPtr outHandle = new IntPtr(); - bool result = ScpDevice.RegisterNotify(this.Handle, hidGuid, ref outHandle); + bool result = ScpDevice.RegisterNotify(this.Handle, hidGuid, ref regHandle); if (!result) { ScpForm_Closing(this, @@ -1080,11 +1080,6 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question } break; } - case WM_CLOSE: - { - ScpDevice.UnregisterNotify(Handle); - break; - } case WM_QUERYENDSESSION: { systemShutdown = true; @@ -2176,6 +2171,14 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question e.Cancel = true; return; } + else + { + ScpDevice.UnregisterNotify(regHandle); + } + } + else + { + ScpDevice.UnregisterNotify(Handle); } } else if (userClosing && closeMini && !contextclose)