I have a DLL in which I have a function that returns a pchar. (as to avoid having to use borlndmm) What I was doing originally was casting a string as a pchar and returning that
DLL and your main app have two different memory managers, so it is incorrect to allocate memory in DLL but free it in main app and vice versa.
You can use WideString type for returning string from dll or passing it to dll — WideString is a wrapper around system BSTR type and memory for WideString variables is allocated automatically by system memory manager.
Another solution is to use SimpleShareMem instead of ShareMem (Delphi 2007 and older only) — it works like ShareMem but does not need any borlnmm.dll-like libraries to redistribute.