With __declspec(dllimport)
a __imp__
before the named method is set.
In the generated delphi CheckFunctions.dll
there is only a function named CheckResult
.
VS C++ 2010 is looking for __imp__CheckResult
. Therefore, the linker VS C++ can not find this function.
You have to create a .lib file.
With the program lib.exe
this .lib file can be created very easily.
Run LIB.exe from the Visual-studio command-prompt.
LIB creates standard libraries, import libraries, and export files you can use with LINK when building a program.
Overview of LIB
If we have created, with the Visual-studio command-prompt>
C:\VisualStudio100\VC>lib /def:C:\CheckFunctions.def /OUT:C:\CheckFunctions.lib
the CheckFunctions.lib
file __imp__CheckResult
can be found.

You can test it with following steps
with Delphi5 and Win xp 32 it works.
CheckFunctions.dpr
library CheckFunctions;
uses
SysUtils,
Classes;
{$R *.RES}
function CheckResult:integer; stdcall;
begin
result:=12000;
end;
exports
CheckResult;
begin
end.
Create the def file
CheckFunctions.def
EXPORTS
CheckResult
Create the lib file
Visual Studio command
C:\Programme\VisualStudio100\VC>lib /def:C:\pathToProject\CheckFunctions.def /OUT:C:\pathToProject\CheckFunctions.lib
Copy CheckFunctions.exp
and CheckFunctions.lib
to
your Visual C++ 2010 Project folder
Visual C++ 2010 CallDll.cpp
#include "stdafx.h"
#define MY_DLL __declspec(dllimport)
extern "C"
{
MY_DLL int CheckResult();
} ;
int _tmain(int argc, _TCHAR* argv[])
{
int myint = CheckResult();
printf ("Decimals: %d \n", myint );
return 0;
}
Update:
if you want it with __stdcall
NEW Visual C++ 2010 CallDll.cpp
#include "stdafx.h"
#define MY_DLL __declspec(dllimport)
extern "C"
{
MY_DLL int __stdcall CheckResult();
} ;
int _tmain(int argc, _TCHAR* argv[])
{
int myint = CheckResult();
printf ("Decimals: %d \n", myint );
return 0;
}
change delphi exports
exports
CheckResult name 'CheckResult@0';
Change
CheckFunctions.def
EXPORTS
CheckResult@0
- Create a new CheckFunctions.lib
That works too.