I have got a DLL and a program, both written with Delphi 2007. The program passes an interface, which descends from IInterface and does not have a GUID (so no COM here) to the DLL which stores it for later use.
This seems to work fine but sometimes I get access violations when the program is closed and the DLL is unloaded. I am not sure about the reason for these AVs. It could be possible that the interface gets out of scope and through reference counting the underlying object, which resides in the program's context, gets freed causing memory corruption because there are two different memory managers involved.
I am not using sharemem and I don't want to for various reasons (one being that there are other programs that are not written in Delphi might want to use that DLL).
I know that I should not pass Strings, open arrays and objects in this manner, but should interfaces work?