w32 api (hooking) : Problem with GetProcAddress and callback (__stdcall) function
-
I have a function inside a DLL that acts as a hook procedure. it has an __stdcall attribute. When i tried to retrieve the function pointer via another exe with GetProcAddress it always fails, and it only works after i remove the __stdcall attribute. How can i retrieve the function pointer of this callback function properly? Is there any difference in the way of retriving function pointer of regular function and callback function? *** code *** this is the hookproc function: LRESULT CALLBACK HookProc(int nCode, WPARAM w, LPARAM l) { return CallNextHookEx(NULL, nCode, w, l); } and this is how i call it in another exe: FARPROC HookProc = NULL; HookProc = GetProcAddress(HookDLL, "HookProc"); *** end of code *** thank you very much. - Ganeshwara
-
I have a function inside a DLL that acts as a hook procedure. it has an __stdcall attribute. When i tried to retrieve the function pointer via another exe with GetProcAddress it always fails, and it only works after i remove the __stdcall attribute. How can i retrieve the function pointer of this callback function properly? Is there any difference in the way of retriving function pointer of regular function and callback function? *** code *** this is the hookproc function: LRESULT CALLBACK HookProc(int nCode, WPARAM w, LPARAM l) { return CallNextHookEx(NULL, nCode, w, l); } and this is how i call it in another exe: FARPROC HookProc = NULL; HookProc = GetProcAddress(HookDLL, "HookProc"); *** end of code *** thank you very much. - Ganeshwara
goto www.dependencywalker.com [^]and download the tool - use it to see how your function is being exported. You can use a .DEF file to control how your function is being exported (see MSDN for details). You can also use the /EXPORT linker switch if you are using visual-c james
http://www.catch22.net -
goto www.dependencywalker.com [^]and download the tool - use it to see how your function is being exported. You can use a .DEF file to control how your function is being exported (see MSDN for details). You can also use the /EXPORT linker switch if you are using visual-c james
http://www.catch22.net -
I have a function inside a DLL that acts as a hook procedure. it has an __stdcall attribute. When i tried to retrieve the function pointer via another exe with GetProcAddress it always fails, and it only works after i remove the __stdcall attribute. How can i retrieve the function pointer of this callback function properly? Is there any difference in the way of retriving function pointer of regular function and callback function? *** code *** this is the hookproc function: LRESULT CALLBACK HookProc(int nCode, WPARAM w, LPARAM l) { return CallNextHookEx(NULL, nCode, w, l); } and this is how i call it in another exe: FARPROC HookProc = NULL; HookProc = GetProcAddress(HookDLL, "HookProc"); *** end of code *** thank you very much. - Ganeshwara
I also STRONGLY reocmmend you call your
HookProc
something ELSE. That name is too common and might also get you into trouble with other linkage and project dependencies later. No shirt, no shoes, no brains, no service.