Corrected unregister notify call

Changed location and corrected used handle
This commit is contained in:
Travis Nickles 2018-10-24 21:41:29 -05:00
parent dfcc3250cf
commit 687ff05948

View File

@ -57,6 +57,7 @@ namespace DS4Windows
bool turnOffTemp; bool turnOffTemp;
bool runningBat; bool runningBat;
private bool changingService; private bool changingService;
private IntPtr regHandle = new IntPtr();
private static DS4Form instance; private static DS4Form instance;
Dictionary<Control, string> hoverTextDict = new Dictionary<Control, string>(); Dictionary<Control, string> hoverTextDict = new Dictionary<Control, string>();
// 0 index is used for application version text. 1 - 4 indices are used for controller status // 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(); Guid hidGuid = new Guid();
NativeMethods.HidD_GetHidGuid(ref hidGuid); NativeMethods.HidD_GetHidGuid(ref hidGuid);
IntPtr outHandle = new IntPtr(); bool result = ScpDevice.RegisterNotify(this.Handle, hidGuid, ref regHandle);
bool result = ScpDevice.RegisterNotify(this.Handle, hidGuid, ref outHandle);
if (!result) if (!result)
{ {
ScpForm_Closing(this, ScpForm_Closing(this,
@ -1080,11 +1080,6 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
} }
break; break;
} }
case WM_CLOSE:
{
ScpDevice.UnregisterNotify(Handle);
break;
}
case WM_QUERYENDSESSION: case WM_QUERYENDSESSION:
{ {
systemShutdown = true; systemShutdown = true;
@ -2176,6 +2171,14 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
e.Cancel = true; e.Cancel = true;
return; return;
} }
else
{
ScpDevice.UnregisterNotify(regHandle);
}
}
else
{
ScpDevice.UnregisterNotify(Handle);
} }
} }
else if (userClosing && closeMini && !contextclose) else if (userClosing && closeMini && !contextclose)