windows - Why Doesn't External Triggering of System Beep Trigger Hooked Code? -


this code works expected "cin" line removed , "beep(750, 300);" uncommented: beep "caught" hook function.

when run is, open shell, , hit control-g, followed enter, triggers system beep- beep doesn't seem triggering print statement in code. tried sleep(30000), didn't work either.

#include "stdafx.h" #include "mhook-lib/mhook.h"  #include <iostream> using namespace std;  // goal: detect use of 'beep' function via hook  // define _beep in order dynamically bind function (what function???) typedef bool (winapi *_beep)(dword, dword);  // backup address of beep function, need restored after hooking _beep backupaddress_beep = (_beep)getprocaddress(getmodulehandle(l"kernel32"), "beep");  // function inserted before beep function once hook in place bool winapi hookbeep(dword dw_freq, dword dw_duration) {     printf("***** call beep(%u, %u).\n", dw_freq, dw_duration);     // continue chain: send beep required params     return backupaddress_beep(dw_freq, dw_duration); }  int wmain(int argc, wchar* argv[]) {     //handle hproc = null;      printf("testing beep.\n");     if (mhook_sethook((pvoid*)&backupaddress_beep, hookbeep)) {         // happens if external program initiates beep, rather ourselves? loop until keyboard break?         //beep(750, 300);         int x;         cin >> x;         // remove hook         mhook_unhook((pvoid*)&backupaddress_beep);     }      return 0; } 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -