Hook procedure (SetWindowHookEx)

Hey
I am trying to use SetWindowHookEx() API to inject my code into another process, but I am kinda lost with the hook procedure that should be placed in the .dll file
is there an explaination about how to build a hook procedure?
thanks in advance!
[275 byte] By [Dody] at [2007-11-20 0:16:56]
# 1 Re: Hook procedure (SetWindowHookEx)
There are several good examples on SetWindowsHookEx on both dev-archive and CodeProject (and in MSDN as well)... search

Can you be more specific about the hook procedure problem you're having?

Also, read about "systemwide hooks" in MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_hooks32.asp
j0nas at 2007-11-9 13:23:24 >
# 2 Re: Hook procedure (SetWindowHookEx)
this is my callback function

LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode<0)
return CallNextHookEx(0,nCode,wParam,lParam);
if (wParam == WM_RBUTTONDOWN)
{
MessageBox(GetForegroundWindow(), "Yes", "Works", MB_OK);
}
return CallNextHookEx(0,nCode,wParam,lParam);
}

and in onbutton function I set:

HOOKPROC wlm;
HHOOK check;
HINSTANCE WLMDLL;

WLMDLL = LoadLibrary((LPCTSTR) "MyHook.dll");
wlm = (HOOKPROC)GetProcAddress(WLMDLL, "MouseProc");

check = SetWindowsHookEx(WH_MOUSE,wlm,WLMDLL,0);

as you can see I am trying to do a mouse hook, this try is to get any right click, but later when I get it to work, I want it to be for a defined application that when it gets right click the the popup pops up

can you see what I am doing wrong in my code?

thanks in advance!
Dody at 2007-11-9 13:24:34 >
# 3 Re: Hook procedure (SetWindowHookEx)
If you really want a global hook (specifying 0 as last arg to SetWindowHookEx), the hook proc must reside in a DLL.

I'm not sure how you have setup everything... Have you exported the MouseProc function? (ie does GetProcAddress work?) Check every return values when installing the hook.

I wrote a simple test in C with VC2003... see attachment.
j0nas at 2007-11-9 13:25:32 >
# 4 Re: Hook procedure (SetWindowHookEx)
thanks alot, I am taking a look at your code..
Dody at 2007-11-9 13:26:27 >