0

I'm new to MFC.

I'm trying to make a DLL in MFC, which links to another DLL.

The problem is when I try and compile, I get a LNK2019 error thrown at me for a function present in the DLL which I'm trying to link.

LNK2019 is when the DLL or the function inside the DLL is not being found.

I've taken all steps, the DLL is placed in a known location, the lib is placed in a known location too, it's been added in the additional dependencies, all correct switches have been applied ( ones I know of anyway ).

I've used Dependency walker and I know the DLL, to which I'm trying to link, exposes this function. I've other examples of use of the function, and I'm trying to use it exactly like it. The .lib and .dll are in agreement, i.e., they're consistent with each other.

But still the error persists.

EDIT This is the error message :

Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall PwServer::Connect(wchar_t const *,unsigned long,unsigned long *)" (_imp?Connect@PwServer@@QAE_NPB_WKPAK@Z) referenced in function "public: bool __thiscall CPwServer::Connect(class ATL::CStringT > >,unsigned long,unsigned long *)" (?Connect@CPwServer@@QAE_NV?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@KPAK@Z)

And this is the call I use to access the DLL.

bool conn = PwSrv->Connect(_T(""));

Dumpbin Export of the function :

25BE6 ?Connect@PwServer@@QAE_NPBGKPAK@Z 25BE6 __imp_?Connect@PwServer@@QAE_NPBGKPAK@Z

Is there something else which needs to be dine in case of linking a MFC DLL with a regular one, like adding AFX_EXT_ or something?

Kindly advise in this. Thank you.

UPDATE

Seems all that was required was to toggle the flag set in Project Properties>>C/C++>>Language>>Treat wchar_t as a built in type to NO. I'd never bothered with the flag before, so didn't know. The Linker error was there...

OK. Now I've another problem. The toggling of wchar_t solved the problem of the DLL linking with another MFC DLL, but now my application cannot find the entry point in my DLL. In dependency walker, it shows a mismatch between CString which the application is sending, and the Unsigned Short..which my DLL is accepting ( as a result of thewchar_t turned off, presumably )

4

1 回答 1

0

Assuming you correctly included the .lib file for the DLL (most of the time this is down to differences in the compiler settings. e.g. UNICODE setting).

  1. Check that the .lib is actually being loaded by setting the 'Show Progress' Linker settings to VERBOSE.
  2. Run DUMPBIN on the LIB file to check that the exported functions are the same as the ones the linker is trying to import.

ie

dumpbin /ALL mylib.lib > exports.txt

If the name decoration is slightly different that'll give you a clue as to the problem.

于 2013-08-19T09:33:51.973 回答