0

I am trying to understand and anticipate how to reference functions in a DLL.

When we reference some functions in a couple of DLLs that we are accessing to do some calculations, in some of the functions, we simply use the process name as the argument lpProcName (e.g. "my_calc_function"). However, in some of the other functions (for a different DLL) we have to add various decorations to the lpProcName (e.g. "?my_other_calc_function@@YA....")

in one case

m_lpfn_my_calc_function_pointer = (lpfn_my_calc_func)::GetProcAddress(m_hOneDll,"this_address_works");

in another case

m_lpfn_my_other_calc_function_pointer = (lpfn_my_calc_func)::GetProcAddress(m_hAnotherDll,"?this_address_has@@YAXNPEAN00PEAH@Z");

Both of these work, however, I would like to understand what the decorations mean and where I can reference them so that I can anticipate them when I am writing my code.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Cool-Dr-T
  • 21
  • 3
  • You may want to read up on name mangling. – NathanOliver Apr 23 '19 at 13:15
  • 1
    Possible duplicate of [Is there a way to find the C++ mangled name to use in GetProcAddress?](https://stackoverflow.com/questions/16016732/is-there-a-way-to-find-the-c-mangled-name-to-use-in-getprocaddress) – vandench Apr 23 '19 at 13:26
  • thanks for the suggestion, it doesn't really help (other than pointing out that there is a name for what I am looking at!) - I am more looking for the system used in the 'mangling' – Cool-Dr-T Apr 24 '19 at 12:47

1 Answers1

0

The decorations (or, name mangling) are based to the fact that you can have functions with the same name but different arguments.

DLL exports do not include function signatures, only a name. Therefore, the name is "decorated" to reflect on these arguments (classes, namespaces, arguments, return type, calling convention etc).

To remove the decoration, declare the function inside an extern "C" block.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78
  • thanks, I don't necessarily want to remove the name mangling, I recognise that it has a use for the various overloads, they are legacy DLLs and have lots of them. I am more looking for a system behind it... if there is any! – Cool-Dr-T Apr 24 '19 at 12:46