+4  A: 

Is ShareMem the first unit in all Delphi DLL and EXE project files? FastMM is already the RTL's memory manager for the past few releases of Delphi.

I would recommend not sharing objects at all between DLLs and EXEs; it's just a recipe for pain. Use packages instead.

If you must use DLLs, I'd advise adopting the usual WinAPI conventions: stdcall calling convention, only using C-compatible data types (integers, floats, pointers, records that have no fields of managed types like strings, arrays or interfaces). Have the DLL do no allocation of memory that the EXE is responsible for freeing. Instead, let the EXE allocate and pass the DLL the memory; alternatively, encapsulate allocations into logical handles, and export functions that dispose of the memory from the DLL, along the lines of e.g. how the CloseHandle WinAPI function works.

Barry Kelly