In Delphi in my DLL do I have to allocate the return pchar of a function

后端 未结 3 512
长情又很酷
长情又很酷 2021-02-14 09:20

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

3条回答
  •  悲&欢浪女
    2021-02-14 09:53

    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.

提交回复
热议问题