我想理解它的原因是我要制作一个像这样的DLL加载器类:
class DymanicLibraryLoader
{
//some code
template <typename FnPtrT>
FnPtrT GetFunction(std::type_info& fn_type, std::string_view pretty_name)
{
//code
}
};
//...
DynamicLibrary dll {...};
typedef void (SomeClass::* FnPtr)(int);
std::type_info& fntype = typeid(FnPtr);
auto fnptr = dll.GetFunction(fntype, "function")
//...
你试过吗
std::typeinfo::raw_name()
?
通常的方法是在使用 dumpbin(包含在 MSVC 中)等工具构建后检查 DLL 导出。
dumpbin /exports <filename>.dll > exports.txt
然后打开exports.txt并在列出的导出中查找您想要加载的函数。如果您希望使用运行时符号加载,我不知道有任何自动方法可以执行此操作。 (使用 __declspec(dllexport)/__declspec(dllimport) 执行加载时绑定很容易),但这不适用于运行时加载。