Get signature from C++ function name?

Started by
13 comments, last by Antheus 14 years, 2 months ago
Once a DLL is compiled, all type information is lost. You can infer some of that information from the mangled name, but not all of it (only basic types such as int, float, as I mentioned above). Name mangling in C++ is not really meant to solve this problem anyway, it's just required so that method overloads will generate unique exported names from the DLL.

It's also totally non-standard. Here's a table showing how different compilers will mangle a function. I guess it's OK if you're going to assume everything is compiled with VC++, but obviously it's not portable (for example, the mingw compiler uses the GCC mangling form).

If you really want to be able to do runtime reflection, you need something like COM or .NET.
Advertisement
If you do the dll yourself and want an easy way to export functionality I usually make on function that exports a class interface.
The code that uses the DLL would need the interface header tho so that might not be what you want :)

Having a common interface also allows you do load different versions of the dll (OpenGL/D3D render for instance) which is handy for a dll based plugin system
Quote:Original post by Codeka
Once a DLL is compiled, all type information is lost. You can infer some of that information from the mangled name, but not all of it (only basic types such as int, float, as I mentioned above). Name mangling in C++ is not really meant to solve this problem anyway, it's just required so that method overloads will generate unique exported names from the DLL.

It's also totally non-standard. Here's a table showing how different compilers will mangle a function. I guess it's OK if you're going to assume everything is compiled with VC++, but obviously it's not portable (for example, the mingw compiler uses the GCC mangling form).

If you really want to be able to do runtime reflection, you need something like COM or .NET.


Hmmm I didn't think about that, I have it working but now that you brought that up I think I'll need to find another way to do this... Probably going to use something like a header in script, not sure about the details yet though but I'll figure something out...
Quote:Original post by Codeka
Once a DLL is compiled, all type information is lost. You can infer some of that information from the mangled name, but not all of it (only basic types such as int, float, as I mentioned above). Name mangling in C++ is not really meant to solve this problem anyway, it's just required so that method overloads will generate unique exported names from the DLL.

It's also totally non-standard. Here's a table showing how different compilers will mangle a function. I guess it's OK if you're going to assume everything is compiled with VC++, but obviously it's not portable (for example, the mingw compiler uses the GCC mangling form).

If you really want to be able to do runtime reflection, you need something like COM or .NET.


Well, as I mentioned earlier if you have a PDB you can do it with the DIA SDK. That's what a debugger (like VS) does. But it's highly nontrivial, and I'm guessing he doesn't want to require there be a PDB around in order for his code to work.
There is 'dumpbin /exports' and 'undname' as part of visual studio.

This topic is closed to new replies.

Advertisement