Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange string behaviour with dll call

Tags:

string

dll

delphi

I have a Delphi 2007 Program, which calls a Delphi 2010 DLL. The Program is big and not yet ported to 2010, so there is no way i can change this right now.

I use SimpleShareMem Unit to pass strings but also tried ShareMem with borlndmm.dll.

For one function i now pass a string from the Delphi 2007 programm to the dll (Therefore AnsiString). When debugging the dll, this AnsiString looks normal and can be viewed in the watch list. But if i do a simple think like

AnAnsiString := PassedAnsiString;

the variable AnAnsistring gets the value '???????'#0#0#0'???A', but PassedAnsiString is still readable in watchlist. Also a string append like

AnAnsiString := PassedAnsiString + NotPassedAnsiString;

uses '???????'#0#0#0'???A' as value.

Where is the problem? Is it a 2007 <-> 2010 issue? How to fix it? Thanks for help.

like image 347
Marks Avatar asked Sep 22 '10 09:09

Marks


1 Answers

This is probably because an encoding field that was added to ansistring in D2009. IOW the record (TAnsiRec) at negative offset of the ansistring pointer is different and shifted between unicode and non unicode Delphi's (ansistring changed too in unicode versions!)

I don't think there is a decent solution for this except dropping back to p(ansi)char level

like image 176
Marco van de Voort Avatar answered Sep 22 '22 06:09

Marco van de Voort