views:

284

answers:

3

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?

+4  A: 

Make sure the _Foo parameter is a widestring in 2010

Zartog
A: 

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
+2  A: 

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.

Serg