Exchanging strings (PChar) between a Freepascal compiled DLL and a Delphi compiled EXE

前端 未结 3 1544
名媛妹妹
名媛妹妹 2020-12-30 16:13

After a lot of experimentations, I found a way to exchange PChar from a FreePascal compiled DLL with a Delphi compiled EXE. I\'m in charge of both the DLL and EXE source cod

3条回答
  •  死守一世寂寞
    2020-12-30 16:39

    Depending on what data you're passing, you may be able to use WideStrings instead. They're allocated on the Windows heap, so if you allocate one in the DLL and free it in the EXE they'll both go through the same memory manager.

    You should be able to use a function declaration like this:

    procedure GetAString(var Result: WideString); stdcall;
    

    And Delphi and FreePascal will both handle the allocation and freeing automatically. WideString is the same in the Unicode-enabled Delphis as the pre-Unicode ones, so you won't need to change things for that either.

提交回复
热议问题