Hello, I am stucked for few days and dont know what to do.
I am working on a library written in c++ (the result is dll), which contains several functions. The DLL itself isnt using MFC, and is singlethread. These functions are then called from delphi application. Example of a function:
extern "C" __declspec(dllexport) int open(void)
All the functions have to return int, because it is used to detect, wheather the function failed. Although, result of some functions has to be string also. This string is passed as a function parameter. Example:
extern "C" __declspec(dllexport) int getName(int index, char* &name)
And here comes the problems. After the whole function is executed, the string variable contains correct data (which is good), but somewhere (I dont know where) is being memory corrupted, which also corrupts some variables in delphi app.
I blanked all the functions like this:
extern "C" __declspec(dllexport) int getName(int index, char* &name)
{
return 0;
}
The memory is being corrupted still. (Unwanted change of delphi variables occures by this "string" type of functions).
I will appreciate any type of help, because I really dont know, what could cause this problem.
Thank you.
Edit: Added some delphi code:
n := getCount;
if n<0 then exit;
else
if n=0 then
else
if n>1 then
status := getName(0,tmp);
if status<0 then exit;
status := getTown(0,tmp);
if status<0 then exit;
n is the mystery modified variable.
Edit2: just tried to create a c++ console app, where could I test correct calling of methods from dll and everything works fine, so problem seems to be in delphi, maybe in calling and allocating memory for methods or whole dll.
FINAL EDIT: The problem is solved: you have to define def files and use stdcall