winapi - How to port the C++ SetWindowsHookEx to C# or is this not possible? -
i looking @ example in microsoft kb318804 use threadid of "current" application!!! have c++ code works have rewrite it, , prefer re-write in c# while in there. 1 thing threadid of target application so:
uint lastid = getwindowthreadprocessid(targethandle, intptr.zero);
no, getcurrentthread not correct call getting thread id of remote application today , want do. targethandle handle remote application.
i cast lastid int , tried wire c# code setwindowshookex returns 0 , fails. appdomain.getcurrentthreadid() seems work (even though deprecated, replacement though doesn't work either).
do have go c++ code then? or there way work in c#?
currently register hookhandler in c++ other application , events back.
have checked out pinvoke.net entry setwindowshookex
?
if setwindowshookex
returns null
, supposed call getlasterror
, in c# should call marshal.getlastwin32error
(assuming dllimportattribute.setlasterror
included on p/invoke signature.)
from pinvoke.net:
signature
[dllimport("user32.dll", setlasterror = true)] static extern intptr setwindowshookex(hooktype hooktype, hookproc lpfn, intptr hmod, uint dwthreadid);
calling
intptr hhook; using (process process = process.getcurrentprocess()) using (processmodule module = process.mainmodule) { intptr hmodule = getmodulehandle(module.modulename); hhook = setwindowshookex(hooktype.wh_keyboard_ll, hook, hmodule, 0); }
possibly related questions:
Comments
Post a Comment