1

I'm writing a DLL to replace a much older one. The new version adds a new function, foo() that is more useful than bar() in the older DLL and effectively replaces it. However, I still need to have a usable bar() for legacy support. What I want are both foo() and bar() to be externally accessible, so I've written a bar() that calls the newer foo().

Header file:

extern "C" void* __stdcall foo();
extern "C" void* __stdcall bar();

DLL main file:

extern "C" void* foo() {}
extern "C" void* bar()
{
    foo();
}

Upon attempting to build, though, Visual Studio gives me

error LNK2019: unresolved external symbol _bar@20 referenced in function _wmain

I suspect I'm having some kind of scope issue, since the only unique thing about bar() seems to be that it calls other functions in the main DLL.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Sarkreth
  • 290
  • 2
  • 10
  • Do you have any kind of main function? – Grantly Dec 19 '14 at 01:57
  • 1
    You probably didn't include your header in your dll implementation. The function prototype likely defaulted to `__cdecl` instead as a result. – greatwolf Dec 19 '14 at 01:58
  • Do you have a definition for `bar()`? You're not showing any. Also the linker error message asks for a mangled name of `bar()`, is it seen elsewhere as a declaration without the surronding `extern "C" {}` block? – πάντα ῥεῖ Dec 19 '14 at 02:12
  • @Grantly _"Do you have any kind of main function?"_ DLL's don't require a `main()` function as entry point. – πάντα ῥεῖ Dec 19 '14 at 02:14
  • 1
    They certainly can, not all but many want a DLLMain for example...his compiler looks like its expecting one... – Grantly Dec 19 '14 at 02:23
  • @Grantly Can't see how this is related to the actual problem though. – πάντα ῥεῖ Dec 19 '14 at 02:30
  • seeing the code for the _wmain function - which may or may not be the entry point ... Will show if he has written this correctly, if it is wrapped in extern or not, and might show more header files or missing header files. That's my choice to approach his problem this way – Grantly Dec 19 '14 at 02:34
  • In the main file you must include the `__stdcall` in the function definition. To get the compiler to detect this, make sure the main file is including the header. – M.M Dec 19 '14 at 03:54
  • Also, declaring the functions as `(void)` would be a good idea (in C++ it's the same, but in C `()` means something different to `(void)` and conceivably this could cause a problem – M.M Dec 19 '14 at 03:56
  • DLL's shouldn't have `_wmain`. Are you perhaps compiling an executable which is trying to link to your DLL's export library or something? – M.M Dec 19 '14 at 03:58

0 Answers0