I have DLL file which compiles in Delphi, functions export as __stdcall, and functions description txt file. I havn't got any source code.
And I'll use this DLL in visual studio c++ project. Google says that need use LoadLibrary + GetProcAddress
, but GetProcAddress returns NULL if exported function declared as __stdcall, i.e. I can't call function with its name. And others recomended using .def file,
but I don't know what .def file, and what need for generating .def file, if I can use this way on my situation, please describe thoroughly.
QA: How I can call these exported functions?
Here I post my main.cpp file, dll name and function name changed specially.
#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 ;
}