I created a function in delphi as below:
function CheckResult():integer; stdcall; export;
The compiler is Delphi 64 and the output is CheckFunctions.dll
Then
in the VC++ project (VS 2012),
I write:
extern "C" __declspec(dllimport) int __stdcall CheckResult();
and use it in a function, then I get the compiler error in C++ project:
error LINK2019: unresolved external symbol __imp_CheckResult referenced in function *
How can I do? Thanks
You are missing an import library (.lib file) for the DLL. That's why the linker is giving that error message. Unfortunately Delphi won't generate a .lib file which is a bit of a weakness in my view.
You can solve the problem by either:
Option 2 is easy enough. Create a fake DLL project in Visual Studio. Arrange for it to export the same functions as your Delphi DLL. Implement these functions with empty stubs. Use a .def file rather than __declspec(dllexport) to avoid name decoration of your exports.
It's really obvious really. Make a fake DLL that has an identical interface to the real DLL. The same name, the same functions. The fake DLL needs no implementation because all you are doing is getting the MS tools to make the .lib file that Delphi cannot.
More details here: http://support.microsoft.com/kb/131313
FWIW I believe that the Delphi export modifier is ignored. Use an exports clause instead.
Use VC's command-line LIB utility to create a VC-compatible import .lib file for the DLL, then add that file to your VC project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With