c++ - SetWindowsHookEx succeed but callback function is never called -


dll code:

lresult callback cbtnewproc(int ncode, wparam wparam, lparam lparam) {      std::ofstream file;     file.open("e:\\enter.txt", std::ios::out);     file << ncode;     file.close();      return callnexthookex(g_hhook, ncode, wparam, lparam); }   extern "c" __declspec(dllexport) void installhook() {     if (g_hhook != null){         unhookwindowshookex(g_hhook);         g_hhook = null;     }     hinstance hinstance = getmodulehandle(null);     g_hhook = setwindowshookex(wh_cbt, cbtnewproc, null, getcurrentthreadid());     if (g_hhook == null)     {         messagebox(null, l"fail!", l"caption", mb_ok);     }     else     {         messagebox(null, l"install success!", l"caption", mb_ok);     } } 

i wrote program load dll , called installhook. message box "install success" showed callback function never called, enter.txt not found under drive e.

i'm using win7 + vs2013.

for hook set in other processes, must pass hinstance of dll contains hook proc setwindowshookex.

you should pass 0 thread id.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -