From a c app (VS2008, Win), I call a function in a dll written in Delphi in Borland. The function works, but after each call I get this error: “The value of ESP was not properly saved across a function call[…]” which means my calling convention is wrong. I don't know Delphi and I don't have the full dll code, but I believe this is the Delphi function:
function translate(file1, file2: PChar):PChar; stdcall;
...
Result:=PChar(c);
end;
exports
translate;
The relevant part in c:
typedef char*(__stdcall *translate)(char*, char*);
translate MyTranslate;
...
MyTranslate = (translate)GetProcAddress(dll, "translate");
char* result = (*MyTranslate)(file1, file2);
Instead of __stdcall in c above I've tried __cdecl and __fastcall, but I always get the ESP message. Also, in the Dephi function code the function seems to return char*, but the dll doc says it returns "true" or "false" (?). So in c instead of "typedef char*..." I've tried "typedef BOOL...": still, I get the ESP message. I know I can suppress the message under "Basic Runtime Checks" (see here), but I'd rather get the calling syntax right. The dll is compressed with UPX, but I'm not sure if it's relevant (like I said, the function itself works).