简体   繁体   中英

How to call a function with types known at runtime

After loading a dynamic library and GetProcAddress , one typically get a function pointer of type void* . To call the function, when doing it at compile time, one would cast the pointer into the correct pointer type needed.

However, if the type is not known at compile time but at runtime instead, and there's many possibilities of the type. In this scenario, it seems one would need to "Call" the function manually, aka, update the stack and registers according to the ABI.

The question is: Is there any open source code that takes care of this in common platforms and ABI? If not, how do I implement one myself?

The Microsoft abi documentations have some things on the cdecl and other conventions, and it seems 32bit and 64bit are different. Is ABI on Linux the same or something else?

In another answer I said that https://dyncall.org/ looks to be what is needed.

That answer was deleted, despite comments saying it was correct. Re-posting the information here in case anyone else needs it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM