Call Function from Dynamic Library

2019-02-17 10:14发布

What would be the best way to, if possible, load a dynamic library and call one of it's functions, when we don't know the name of the function during compile-time?

For example, is there a way to make a program that reads a string from a file and then loads a DLL and searches for and calls a function with its name being the string read from the file?

Help would be very much appreciated.

1条回答
我想做一个坏孩纸
2楼-- · 2019-02-17 10:48

There is an example on Wikipedia of all places showing how to use the LoadLibrary() function at runtime. You will see that the function name is specified as a string. You would need to write the code to search for the function name and pass it to similar code.

On Linux you can do this with dlopen() and dlsym() functions.

查看更多
登录 后发表回答