Delphi DLL compatible with other programming languages

I want to create a DLL that exports functions that return a string. This DLL should work with other programming languages! I found all sorts of unpleasant solutions / hacks for myself, it is best to force my function to return Pchar, and then call another function contained in the same DLL (let it be called ReleaseMemory) to free up the memory reserved for PChar.

In any case, I recently discovered the FastShareMem library. It says that he can do exactly what I want WITHOUT calling ReleaseMemory. FastMM, on the other hand, seems to do the same as LONG, since both the DLL and the application use FastMM as a memory manager. This will instantly kill the chance to use FastMM as a memory box for my universal DLL. Correctly?

======================

FastShareMem ( http://www.codexterity.com/fastsharemem.htm ), Delphi 7, Windows XP 32 bit, Windows 7 64 bit

+3
source share
4 answers

You are mixing two different scenarios:

  • Delphi Applications Using Delphi DLL
  • Any application using Delphi DLL

, Delphi - , , . , , /. , FastMM FastShareMem, .

DLL , , , , , . PChar, DLL, , , PChar , /. COM , , / , . DLL, .

- PChar. , - , . , Windows, , .

+6

Delphi string, DLL , Delphi. , , . , Windows API .

, - , DLL, - . , , DLL, , . API FormatMessage : , , , LocalFree.

, , , DLL . , Windows API , LocalAlloc LocalFree, SysAllocString SysFreeString. - - , , . , , . , . GetLongPathName.

FastSharemem Delphi, , , . , : DLL , . DLL Delphi, FastSharemem. FastSharemem Delphi, , .

+8

FastSharemem, 2 . , FastSharemem , Delphi. , , .

API Windows , , Microsoft COM (OLE) ; , .

, Windows , , Windows . :

1) API- C (PChars ..) API . , , . API Windows . SDK, stdcall.

2) COM . Delphi , COM. , COM BSTR (WideString Delphi).

, .

+3

, . , (DLL EXE), , , . , , . , GetMem , , , . FreeMem/ , .

, EXE DLL, . EXE DLL-, DLL (PChar), , . EXE, , . EXE , EXE- ! EXE , "" .

DllReleaseString(), DLL DLL .

, , . DLL EXE , DLL- EXE, DLL DLL . , , BOTH DLL EXE- ( !). DLL , EXE - - , DLL "" EXE , EXE ( ).

Therefore, if you want your DLL to be universal, you cannot rely on memory managers talking to each other. Your DLL can be used with EXEs or DLLs that rely on another memory manager, possibly written in another language. Sharing memory managers is only possible when you control all parts of your project and you can explicitly set up the same manager all over the world.

+2
source

Source: https://habr.com/ru/post/1759064/


All Articles