Possibility of 2 function definitions?

I have an external library statically linked in to my program. I would like to know if it is possible to create a 'function' in my code that will get run when the library runs a specific one of it's functions. Simply, my function will be run as well as the original function in the library.


function in external library: void procEventMessage(int type, char* command);
my function: void hookProcEventMessage(int type, char* command);


I would like my function hookProcEventMessage() to be called whenever procEventMessage() gets called outside of my code, but I do not want to completely replace procEventMessage, I would like the program to run both. I am not able to modify the source of the external library, as it is already built.
And why can't you just create proxy functions and then call these proxies instead of the originals in the code that is using the static library?
I'm not the one calling the functions in the library, procEventMessage gets called by the library itself. I'm trying to hook into that function without modifying the library, so when an "event" occurs, my code will run as well. The only way to tell when that event occurs in the library is when that function is called, hence why I'm trying to hook my code into it
I see. Well, theory says you can re-write the function address and make it point to an address of your own. This technique is used by Microsoft's Detours project. Now, how to do this for an arbitrary library? Beats me. :-(

But at least you have something to google about. :-)
Topic archived. No new replies allowed.