如何以编程方式获取 MSVC 中任何类型函数的修饰名称

问题描述 投票:0回答:2

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

class DymanicLibrary
{
    //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")

//...
c++ visual-c++ dll
2个回答
0
投票

您要求的是可能可能,但需要大量代码。 MSVC++ 名称修饰算法很大程度上已进行了逆向工程。请参阅https://en.wikiversity.org/wiki/Visual_C%2B%2B_name_mangling


-1
投票

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

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

然后打开exports.txt并在列出的导出中查找您想要加载的函数。如果您希望使用运行时符号加载,我不知道有任何自动方法可以执行此操作。 (使用 __declspec(dllexport)/__declspec(dllimport) 执行加载时绑定很容易),但这不适用于运行时加载。

© www.soinside.com 2019 - 2024. All rights reserved.