c# - The instructions at 0xXXXXXXXX referenced memory at 0xXXXXXXXX, The memory could not be written -


i error when trying implement windows hook using setwindowshookex , callwndproc. i'm wondering if implemented hook correctly. here code: code work keyboard hook if replaced lowlevelkeyboardproc


    [dllimport("user32.dll")]     static extern intptr setwindowshookex(int idhook, callwndproc callback, intptr hinstance, uint threadid);      [dllimport("user32.dll")]     static extern bool unhookwindowshookex(intptr hinstance);      [dllimport("user32.dll")]     static extern intptr callnexthookex(intptr idhook, int ncode, int wparam, intptr lparam);      [dllimport("kernel32.dll")]     static extern intptr loadlibrary(string lpfilename);      private delegate intptr callwndproc(int ncode, intptr wparam, intptr lparam);      const int wh_callwndproc = 4;     const int wm_paste = 0x302;     private callwndproc _proc = hookproc;      private static intptr hhook = intptr.zero;      public void sethook()     {         intptr hinstance = loadlibrary("user32");         hhook = setwindowshookex(wh_callwndproc, _proc, hinstance, 0);     }      public static void unhook()     {         unhookwindowshookex(hhook);     }      public static intptr hookproc(int code, intptr wparam, intptr lparam)     {         if (code >= 0 && wparam == (intptr)wm_paste)         {             messagebox.show("paste");             return (intptr)1;         }         else             return callnexthookex(hhook, code, (int)wparam, lparam);     }      private void form1_closing(object sender, system.componentmodel.canceleventargs e)     {         unhook();      }      private void form1_load(object sender, eventargs e)     {         sethook();     } 

the module handle passed setwindowshookex should handle dll, not "user32".


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -