c - GCC dll for use with Delphi ShareMem application -
so have host delphi 7 application, has allocate , destroy strings in it's dll. surely, dll written in object pascal , uses sharemem first of , carries borlndmm.dll in it's folder time.
right need rewrite dll in c (mingw preferable) , compile dll main application, written in delphi 7.
how can achieved? need rewrite borland memory manager in c or should write interface use borlndmm.dll?
you need use sharemem when allocating using delphi heap in 1 module, , deallocating them using same heap in different module. sharemem unit ensures memory allocations in both modules share same allocator.
now, can delphi executable , delphi dll, provided both executable , dll compiled same version of delphi. cannot @ delphi executable , c dll. cannot allocate memory in delphi , expect c dll able deallocate it. c runtimes not map malloc/free call shared memory manager.
your question makes clear allocate delphi string in delphi , pass c dll. , free in c dll. cannot reasonably expect that. delphi string has managed delphi runtime. don't have available in c dll.
now, it's possible devise way emulate delphi runtime in c sufficient interop strings. think that's bad idea. instead, should follow standard interop practice:
- arrange memory deallocated in same module allocates it.
- only pass standard interop types between 2 modules. is: integral types, floating point types, null-terminated string pointers. , compound types, records , arrays, contain standard interop types.
update
you state in comments:
the problem don't have soucecode of delphi app.
that leaves in of bind. cannot change interface dll. solution make thin wrapper dll written in delphi 7. wrapper dll should use sharemem , can create strings destroyed host executable. wrapper dll forwards new c dll requests host executable. interop between delphi 7 wrapper , new c dll follows standard interop guidelines.
the wrapper dll known adapter.
Comments
Post a Comment