查资料看到DLL不建议使用string类型,如果使用pchar的话,返回值可以转换成string吗? var InputS,OutPutS:string; begin OutPutS := DLL.func1(InputS); end; 上述写法,DLL链接库的函数的输入和输出都是string类型,好像有些问题,如果改成pchar,大家有什么简单的方法吗?
var s:string; p:pchar;begin s:='AAA'; P:=pchar(s); showmessage(p);{AAA} p:='BBB'; s:=P; showmessage(s);{BBB}end; [解决办法] dll内部可以用string [解决办法] 可以相互转换,很简单 [解决办法] copy on write,没隐患 [解决办法]
[解决办法] 新建 dll 的时候已经说的很清楚了吧 { 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. } [解决办法] DLL,导出函数字符参数,还是用PCHAR吧 [解决办法] Use后边加个shareMem吧! 注:放在第一位! 好用,专门解决这个问题的