[fpc-pascal] Ansistrings exported in DLL's - mystery

L505 fpc505 at z505.com
Tue Jan 3 19:27:53 CET 2006


>
> 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
>

Thanks, and after looking into cmem.pp source code, I see why - it is simply calling
a few simple functions from the operating system libraries. cmem is a very short
simple and small unit. Advantages over sharemem are with cmem you wouldn't have to
ship sharemem.dll with the application.




More information about the fpc-pascal mailing list