BOOL CALLBACK HandleWMCommandHotKey(WPARAM wParam, HWND hwnd) { if (HIWORD(wParam) == BN_CLICKED) { switch (LOWORD(wParam)) { case IDC_RADIO_CLEAR: g_hkdata->keyRevert.Clear(); KeyToDlg(g_hkdata->keyRevert, IDC_EDIT_BREAK, hwnd); return TRUE; case IDC_RADIO_DEFAULT: g_hkdata->keyRevert = g_hkdata->keyDefault; KeyToDlg(g_hkdata->keyRevert, IDC_EDIT_BREAK, hwnd); CheckDlgButton(hwnd, IDC_CHECK_LEFTRIGHT, g_hkdata->keyRevert.GetLeftRightMode() ? BST_CHECKED : BST_UNCHECKED); return TRUE; case IDC_RADIO_TYPE: g_hkdata->keyRevert.Clear(); SetDlgItemText(hwnd, IDC_EDIT_BREAK, L"Press hotkey ..."); return TRUE; case IDC_BUTTON_OK: HandleExit(hwnd, true); return TRUE; case IDC_BUTTON_CANCEL: HandleExit(hwnd, false); return TRUE; case IDC_CHECK_LEFTRIGHT: g_hkdata->keyRevert.SetLeftRightMode(SendDlgItemMessage(hwnd, IDC_CHECK_LEFTRIGHT, BM_GETCHECK, 0, 0) == BST_CHECKED); KeyToDlg(g_hkdata->keyRevert, IDC_EDIT_BREAK, g_hkdata->hwnd); break; } } return FALSE; }
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: #if _M_X64 gDebugLog = GlobalAllocator.New<CDebugLog>("AeonProfiler64.log"); #else gDebugLog = GlobalAllocator.New<CDebugLog>("AeonProfiler32.log"); #endif DebugLog("***** DLL_PROCESS_ATTACH *****"); ModuleHandle = hModule; ApplicationProcessId = GetCurrentProcessId(); ApplicationThreadId = GetCurrentThreadId(); InitializeCriticalSection(&gCriticalSection); SetCriticalSectionSpinCount(&gCriticalSection, 4000); // 4000 is what the Windows heap manager uses (https://msdn.microsoft.com/en-us/library/windows/desktop/ms686197%28v=vs.85%29.aspx) DWORD64 Counter_Freq, Counter_Before, Counter_After; DWORD64 RDTSC_Before, RDTSC_After; QueryPerformanceFrequency((LARGE_INTEGER*)&Counter_Freq); QueryPerformanceCounter((LARGE_INTEGER*)&Counter_Before); RDTSC_Before = __rdtsc(); Sleep(1000); RDTSC_After = __rdtsc(); QueryPerformanceCounter((LARGE_INTEGER*)&Counter_After); ClockFreq = Counter_Freq * (RDTSC_After - RDTSC_Before) / (Counter_After - Counter_Before); TicksPerHundredNanoseconds = (int)(ClockFreq / 10000000); DialogCallTreeThreadId = ApplicationThreadId; // get the current thread id (this should be "main()" or "WinMain()") // Get the process name that's loading us GetModuleFileName( GetModuleHandle( NULL ), app_filename, _countof(app_filename) ); DebugLog("Application: %s", app_filename); DialogThreadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DialogThread, NULL, 0, &DialogThreadID); bTrackCallerData = true; break; case DLL_PROCESS_DETACH: bTrackCallerData = false; DebugLog("***** DLL_PROCESS_DETACH *****"); HandleExit(); if( DialogThreadHandle ) { if (WaitForSingleObject(DialogThreadHandle, INFINITE) == WAIT_TIMEOUT) { TerminateThread(DialogThreadHandle, 0); } CloseHandle(DialogThreadHandle); } DeleteCriticalSection(&gCriticalSection); if( gDebugLog ) { gDebugLog->~CDebugLog(); gDebugLog = nullptr; } break; } return TRUE; }