我有Delphi中编译的DLL文件,函数导出为__stdcall,函数描述txt文件。我没有任何源代码。从Visual C++调用delphi dll
我将在visual studio C++项目中使用这个DLL。谷歌表示需要使用LoadLibrary + GetProcAddress
,但如果导出函数声明为__stdcall,则GetProcAddress将返回NULL,即我无法使用其名称调用函数。和其他人推荐使用.def文件, 但我不知道什么.def文件,以及什么需要生成.def文件,如果我可以用这种方式对我的情况,请详细描述。
问:我如何调用这些导出的函数?
在这里,我发布我的main.cpp文件,dll名称和函数名称专门更改。所有的
#include <Windows.h>
#include <tchar.h>
#include <cassert>
#include <cstdio>
int main()
{
//foo(80, 127);
HMODULE hLib;
hLib = LoadLibrary(_T("MyDLL.dll"));
assert(hLib != NULL); // pass !!
int (__stdcall *pFoo)(int, int);
(FARPROC &)pFoo = GetProcAddress(hLib, _T("foo"));
if (pFoo== NULL)
{
DWORD errc = GetLastError();
printf("%u\n",errc); // it gets error 127
}else{
printf("success load\n");
}
// pFoo(04,1);
FreeLibrary(hLib);
return 0 ;
}