Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
346 Beiträge
 
#10

AW: DLL mit Strings von D10 nach Delphi 6

  Alt 26. Okt 2023, 09:19
Hi,

Is this acceptable to be solved by a hack ?

As i think it is doable but with little hacking around, see the the string structure is different, but we can utilize the fact of how Delphi handle constant (literal) strings, if the reference count is -1 ($FFFFFFFF) then it will always copy it, so in theory which i see doable, you have to overwrite and adjust your returned string to have the same structure as Delphi 6.
so the steps should be like:

1) in Delphi 10 and when the result is ready to returned, a copy of the pointer is stored in a garbage collecting list, this is crucial because we need to fix it later and release the memory preventing leak and corruption in the DLL.
2) rewrite the structure to be compatible with Delphi 6, means overwrite the 16bit "codePage" and "elemSize" as one cardinal 32bit, with value $FFFFFFFF (-1), and put the length in refCount.
3) now Delphi 6 should copy all the returned strings to its own allocated strings, as it will see them as constants.
4) we need an entry point to clean the garbage, it could be the first line in every call to DLL in Delphi 10, to restore the string refcount and assign it to an empty string ''.

This is working in my head and before writing code to demonstrate it and waste time, i would know if this is acceptable, also i don't have now an access to Delphi 6 or 7 to test it with a debugger.

On side note : i saw somewhere that himitsu has a unique love/hate for garbage collectors in Delphi, and i would love to hear your opinions.
Kas
  Mit Zitat antworten Zitat