1

In a dll build with Delphi 2006

Foo(aPath: widestring);
begin
  _rootPath := aPath;
end;

In an executable built with Delphi 2010

_Foo := GetProcAddress(FooModule,’Foo’);
_Foo(‘123456’);

Stepping into the dll, aPath = '123'. In fact any string I pass gets cut exactly in half.

1.) Why is my literal being halved? 2.) How do I fix it?

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
DaiKiraii
  • 43
  • 4

3 Answers3

5

Make sure the _Foo parameter is a widestring in 2010

Zartog
  • 1,906
  • 1
  • 16
  • 27
2

WideStrings reside in Windows heap and are not managed by Delphi memory manager. So WideStrings (unlike other long string types) can be shared between exe and dll without problems.

kludg
  • 27,213
  • 5
  • 67
  • 118
0

I suppose you get wrong data because WideString is a managed type and the memory manager for the dll and the executable are different. If you can recompile the dll make aPath type to be PWideChar

pani
  • 1,075
  • 6
  • 13