void xMain() { MSG msg; g_hEvent = CreateEvent(NULL, TRUE, FALSE, _T("_53_kana_led")); if (g_hEvent == NULL) failed(_T("CreateEvent()")); if (GetLastError() == ERROR_ALREADY_EXISTS) { failed(_T("kana_led is already running!")); } if (SetTimer(NULL, 0, 500, TimerCallback) == 0) failed(_T("SetTimer()")); g_hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHook, GetModuleHandle(0), 0); if (!g_hHook) failed(_T("SetWindowsHookEx()")); OpenKeyboardDevice(); while (GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } CloseKeyboardDevice(); UnhookWindowsHookEx(g_hHook); CloseHandle(g_hEvent); ExitProcess(0); }
extern "C" __declspec(dllexport) int Unload(void) { UnhookWindowsHooks(); if (hModulesLoaded) UnhookEvent(hModulesLoaded); if (hMsgEventHook) UnhookEvent(hMsgEventHook); if (hOptionsInitialize) UnhookEvent(hOptionsInitialize); if (hEnableService) DestroyServiceFunction(hEnableService); if (hDisableService) DestroyServiceFunction(hDisableService); if (hStartBlinkService) DestroyServiceFunction(hStartBlinkService); if (hEventsOpenedService) DestroyServiceFunction(hEventsOpenedService); if (hFlashingEventService) DestroyServiceFunction(hFlashingEventService); if (hNormalizeSequenceService) DestroyServiceFunction(hNormalizeSequenceService); // Wait for thread to exit SetEvent(hExitEvent); WaitForSingleObject(hThread, INFINITE); RestoreLEDState(); CloseKeyboardDevice(); destroyProcessList(); destroyProtocolList(); return 0; }
extern "C" __declspec(dllexport) int Unload(void) { UnhookWindowsHooks(); // Wait for thread to exit WaitForSingleObject(hThread, INFINITE); RestoreLEDState(); CloseKeyboardDevice(); destroyProcessList(); destroyProtocolList(); return 0; }