What you're doing is not necessarily a good idea unless you control the entire build chain and can ensure both your DLL and any apps using it are built with the same version of the same compiler.
With that said, yes, you can load name-mangled functions using GetProcAddress
. Just use Dependency Walker or look at the generated .def file for your DLL, if your compiler is set to produce one, to get the mangled function name. Then you can GetProcAddress
it. You cannot, however, call GetProcAddress
with an unmangled name and expect it to find the right mangled name. For example, if your DLL's function is named Add
, and is mangled to _Z3Addv
, you would need to call GetProcAddress(myDLL, "_Z3Addv");
to access the function properly.
You would need to change the call to GetProcAddress
every time you change the declaration of your function, since the mangled name would also change. Be aware you will also need to change the GetProcAddress
call if you change the compiler your DLL is built with - MSVC's mangling is a lot different from GCC's, and clang's mangling is probably different from both of them. So you might want to reconsider the way you're doing this, since it seems rather prone to breaking somewhere along the way.