widestring compatibility problem in Delphi

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?


确保_Foo参数在2010年是一个宽带


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.


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

链接地址: http://www.djcxy.com/p/61486.html

上一篇: Delphi WideString和Delphi 2009+

下一篇: Delphi中的宽字符串兼容性问题