How can I get the decorated name of a function of any type in MSVC programmatically

Viewed 83

The reason I want to understand it is that I'm going to make a DLL loader class like this:

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")

//...
1 Answers

The usual way would be to examine the DLL exports after building with a tool like dumpbin (included with MSVC).

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

then opening exports.txt and looking through the listed exports for the function(s) you want to load. I am not aware of any automated way to do this if you wish to use run-time symbol loading. (It is easy to perform load-time binding using __declspec(dllexport)/__declspec(dllimport)) but that is not available for run-time loading.

Related