c++ 如何以编程方式获取成员函数的修饰名?(在MSVC中会更好)

mgdq6dx1  于 2024-01-09  发布在  其他
关注(0)|答案(2)|浏览(183)

我想理解它的原因是我要做一个像这样的DLL加载器类:

  1. class DymanicLibraryLoader
  2. {
  3. //some code
  4. template <typename FnPtrT>
  5. FnPtrT GetFunction(std::type_info& fn_type, std::string_view pretty_name)
  6. {
  7. //code
  8. }
  9. };
  10. //...
  11. DynamicLibrary dll {...};
  12. typedef void (SomeClass::* FnPtr)(int);
  13. std::type_info& fntype = typeid(FnPtr);
  14. auto fnptr = dll.GetFunction(fntype, "function")
  15. //...

字符串

ifmq2ha2

ifmq2ha21#

你试过std::typeinfo::raw_name()吗?

s71maibg

s71maibg2#

通常的方法是在使用dumpbin(MSVC中包含)等工具构建后检查DLL导出。

  1. dumpbin /exports <filename>.dll > exports.txt

字符串
然后打开exports.txt文件,在列出的导出文件中寻找你想要加载的函数。如果你想使用运行时符号加载,我不知道有什么自动化的方法可以做到这一点。(使用__declspec(dllexport)/__declspec(dllimport)很容易执行加载时绑定),但这不适用于运行时加载。

相关问题