c++ - Create a function with unique function pointer in runtime -


When calling the WinAPI function that takes callpacks as a callback, there is usually a special parameter for passing some arbitrary data for the callback. If there is no such thing (e.g., the only way we can understand that due to calls given callback calls, there should be separate callback due to the API call. When we know all the cases in which the given API is called at compile-time, we can always create a class template with static method and instantize the different call sides with different template arguments. . This is hell of a work, and I do not like to do this.

How do I create callback functions on runtime so that they have different function pointers?

I saw sorry, in Russian) with runtime assembly generation, but it was not portable in the x86 / x64 architecture.

You can use it to allow you to create each trampolines with a different address I The wrapping class is implemented, although it has not yet been completed (only supports int logic and return type, you only to support more than detail :: type expert can ). A more heavyweight option is LLVM, although if you are working only in C, the libffi job will work fine.


Comments