动态库中的调用函数 [英] Call Function from Dynamic Library

查看:168
本文介绍了动态库中的调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能的话,加载一个动态库并调用其中一个函数,最好的方式是什么?在编译期间我们不知道函数的名称?

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?

例如,有没有办法使程序从文件中读取一个字符串,然后加载一个DLL,并搜索并调用其名称是从文件读取的字符串的函数?

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?

帮助将非常感激。

推荐答案

有一个示例在所有地方的维基百科显示如何使用 LoadLibrary()函数。你会看到函数名被指定为一个字符串。您将需要编写代码来搜索函数名称并将其传递给类似代码。

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.

在Linux上,您可以使用 dlopen()和dlsym()函数。

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

这篇关于动态库中的调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆