-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Supports class methods? #40
Comments
It would probably work if you somehow obtain a pointer to the member function that you wish to hook and declare your function with |
Short: Yes. Long: I had to recast the member function pointer, because my gcc refuses converting it directly to a void * (I casted it to a normal function pointer first). It gets a little bit tricky if the function is a virtual one, because than the member function pointer is an index of the function in the vtable (at least in my gcc version). So you have to get the correct function pointer out of the vtable. You also have some work to do, if the function is private, and you want to set the hook from outside. (Google for "C++ how to access of private members") If you have everything up and running, you get the this pointer as first function argument. Of course you can only use the public members/methods, because you are outside in your C-function. |
Hey there, Can you go into more detail on how you typecasted a class function to a |
|
Thanks for your reply; however the line I see that you're converting the class function pointer |
I'm sorry to hear that, it compiles with a warning (which can be suppressed with -Wno-pmf-conversions) using GCC 13.2 on Linux (I recommend experimenting with different compilers on godbolt.org)
Exactly. |
The README example illustrated hooks for global functions. Do hooks work for instanced class methods (virtual and non-virtual), and method overloads?
The text was updated successfully, but these errors were encountered: