Exporting an undecorated function name

1.8k Views Asked by At

I've read several articles here on name mangling/decoration and keep running into inconsistencies so I thought I would ask a pretty focused question and see what happens.

I am trying to work my way up the learning curve to eventually be able to create a dll in VS2013 that is usable by code generated on a very old Borland C++ compiler. The first step is to build an exe and dll in VS2013 that can "talk". I want undecorated function names. So I have created a dll with one exported function.

extern "C" __declspec(dllexport) int __cdecl BasicFileOpen(void);

My limited understanding is:

  1. extern "C" means no decoration
  2. __declspec(dllexport) means export the function
  3. __cdecl specifies the calling signature (how parameter get put on the stack, etc)

When I examine the dll using DependencyWalker or Dumpbin /EXPORTS, the function name is undecorated. Yay.

Here is the code in the exe that attempts to call the exported function in the dll:

void CCallsCIDdllDlg::OnBnClickedOk()
{
    int iRetVal = BasicFileOpen();

    // TODO: Add your control notification handler code here
    CDialogEx::OnOK();
}

However, when I try to build the exe, I get a linker error.

error LNK2019: unresolved external symbol _BasicFileOpen referenced in function 
"public: void __thiscall CCallsCIDdllDlg::OnBnClickedOk(void)" 
(?OnBnClickedOk@CCallsCIDdllDlg@@QAEXXZ)

Note that the exe mentions _BasicFileOpen. I am puzzled by this. I have correctly pointed at the lib file produced by the dll build. I am including the header file for the dll function in the exe. Why doesn't the linker understand the name of the exported function? Why does it think the function name is decorated? BTW using a .def file does not seem to make any difference.

Any comments are appreciated.

MBB

0

There are 0 best solutions below