Al T 12 Posted November 12, 2022 I'm in a discussion with Skia4Delphi about this and was wondering if anyone here has tackled this problem? Vinícius Felipe Botelho Barbosa says it's nearly impossible and well, I'm curious if anyone has done the impossible? I have the Delphi 11.0 Enterprise Edition. https://github.com/skia4delphi/skia4delphi/discussions/176#discussioncomment-4097532 Thanks for your help in advance! Share this post Link to post
David Heffernan 2345 Posted November 12, 2022 Yes it's exceptionally hard. Just put the code in a DLL. 1 Share this post Link to post
angusj 126 Posted November 12, 2022 (edited) 11 hours ago, David Heffernan said: Yes it's exceptionally hard. Just put the code in a DLL. I think David meant it's NOT exceptionally hard. However, you can't export C++ classes in your DLL. You must use simple structures (records) as parameters in your exported functions, ie structures that can be understood by other languages. The other thing to watch our for is memory management because structures created by DLL functions (ie heap allocoated memory) can't be freed using Delphi's memory manager. Here is an example in my Polygon Clipping library and the C++ export header. Edit: And of course Delphi routinely links to numerous operating system DLLs that would have been written in C and C++. Edit2: I haven't properly researched this but it looks like Delphi's FreeMemory function bypasses Delphi's memory manager and frees heap memory directly. So FreeMemory could probably be used to free structures created by (C++) DLLs. Nevertheless, IMHO, all DLLs that create heap allocated structures - ie any structure returned as a pointer - should also export functions to destroy these structures. Edit: The OP was asking about static linked libraries, and my reply was about dynamic libraries. Sorry. Edited November 13, 2022 by angusj 1 Share this post Link to post
David Heffernan 2345 Posted November 12, 2022 3 hours ago, angusj said: I think David meant it's NOT exceptionally hard. No, I mean that linking C++ static libraries is exceptionally hard, because where do you get the runtime support from? 3 hours ago, angusj said: haven't properly researched this but it looks like Delphi's FreeMemory function bypasses Delphi's memory manager and frees heap memory directly. No. It calls the standard Delphi MM. Also, there's no concept of freeing heap memory directly. That makes no sense. You always have to free from the same heap that was used to allocate. 1 Share this post Link to post
angusj 126 Posted November 13, 2022 (edited) Deleted post to avoid showing my ignorance . (I confused static linking with static binding.) Edited November 13, 2022 by angusj 1 Share this post Link to post