[fpc-pascal] Ansistrings exported in DLL's - mystery
Jonas Maebe
jonas.maebe at elis.ugent.be
Tue Jan 3 19:11:58 CET 2006
On 03 Jan 2006, at 18:49, L505 wrote:
>> A very easy way to solve all problems in FPC is to simply use the
>> cmem unit in the dll(s) and in your main program. It should have the
>> same effect as Delphi's sharemem unit.
>
> Would that work with C programs that called a library? I think
> sharemem only works
> for borland applications (i.e. pascal and C++ builder).
If a Pascal program returns a reference counted type to a C library,
then you get a memory leak, sharemem/cmem or not. If a C program
passes a pchar to a function that expects an ansistring, you can get
any sort of behaviour ranging from no problem to program crashes
(which is logical, since the C program is passing a variable of a
wrong type).
You cannot declare a function as returning an "ansistring" in C,
since C doesn't know the ansistring type. So you cannot properly use
functions which accept or return values of that type from C programs.
It's as simple as that. You simply have to declare your functions
which you want to be callable from C with types that also exist in C
(or which can be constructed to be 100% the same in C).
Jonas
More information about the fpc-pascal
mailing list