views:

272

answers:

1
+5  Q: 

low level Hooker

I want to make a hook that will act like "event" (and not with agly GetAsyncKeyState) in C# (I want to do it in C++). so, I've made a dll with this content: http://pastebin.com/yEHJKSS7 .

well, it doesn't call to Handler Function.

by the way, here's how I used the dll:

void KeysHandler(int vkKey, int flags)
{
    if(vkKey == VK_ESCAPE)
        exit(0);
    File << vkKey << endl << flags << endl;
}

int main
{
    SetHandler(HandlerFunc);
    //sleep here
}

edit: now I saw how I can "debug" in the dll, here are the findings: the SetWindowsHookEx returns 255 - i think it's starnge because it worth to char exactly - I'm going to check in the documentation what does it mean.

edit: 255 is valid return value :O only NULL (0) is error.

I have no idea what's the problem.

edit: well, now my friend brought me a hooker that worked for him. and guess... it didn't work.

I decided it's very strange so I did GetLastError and got 127 - procedure haven't found. I don't see any reason my procedure won't be found, help please :(

+1  A: 

Is your main really only calling SetHandler followed by sleep?

You need a MessageLoop in order for any events to be called.

AShelly
Ohad
OK, I found a direction(I edited ,y question), but I don't know exactly what happen, because my friend told me it works for him.
Ohad