| 4207 | |
| 4208 | |
| 4209 | bool SystemHasAnotherKeybdHook() |
| 4210 | { |
| 4211 | if (sKeybdMutex) |
| 4212 | CloseHandle(sKeybdMutex); // But don't set it to NULL because we need its value below as a flag. |
| 4213 | HANDLE mutex = CreateMutex(NULL, FALSE, KEYBD_MUTEX_NAME); // Create() vs. Open() has enough access to open the mutex if it exists. |
| 4214 | DWORD last_error = GetLastError(); |
| 4215 | // Don't check g_KeybdHook because in the case of aChangeIsTemporary, it might be NULL even though |
| 4216 | // we want a handle to the mutex maintained here. |
| 4217 | if (sKeybdMutex) // It was open originally, so update the handle the the newly opened one. |
| 4218 | sKeybdMutex = mutex; |
| 4219 | else if (mutex) // Keep it closed because the system tracks how many handles there are, deleting the mutex when zero. |
| 4220 | CloseHandle(mutex); // This facilitates other instances of the program getting the proper last_error value. |
| 4221 | return last_error == ERROR_ALREADY_EXISTS; |
| 4222 | } |
| 4223 | |
| 4224 | |
| 4225 | |