Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. 看了这段说明就知道为什么了,这是delphi帮你生成DLL的时候给的一段note
stdcall 是参数传递顺序的一种用 string 作为参数和返回时,要 uses ShareMem
String 用 长度指示
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. 看了这段说明就知道为什么了,这是delphi帮你生成DLL的时候给的一段note
而且我用Try想把错误屏蔽掉,但还是不行
1、在两边都uses ShareMem ,注意:ShareMem 必须放在uses 之后第一个。
2、不在DLL 与EXE 之间传递string,改成传递array[1..BUFF_LEN] of Char,这样虽然比较僵化,却很通用,也可以用来在Delphi 和VC之间传递数据。
3、用COM 接口
更多关于delphi 中的字符串问题,可以参考我写的文章《Delphi 中的字符串》,也许会有帮助。http://www.csdn.net/develop/read_article.asp?id=20753