【紧急求助】 用DELPHI 做的 DLL 返回 PCHAR 类型,返回值一长就会出错,请教如何解决? 100酬谢!

Mylwf 2004-11-26 06:38:14
用DELPHI 做的 DLL 返回 PCHAR 类型,返回值一长就会出错,请教如何解决? 100酬谢!

谢谢!!

返回值短的时候好像没有任何问题
...全文
496 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝色光芒 2004-11-27
  • 打赏
  • 举报
回复
PChar作参数传递时,DLL里一般不要主动申请空间,让调用的程序申请,而且要求调用程序传PChar的长度,如Windows的大多数API函数,DLL里只是对PChar指向的内容填内容就行了。如:GetSystemDirectory,GetTempPath,等等,
beyondtkl 2004-11-27
  • 打赏
  • 举报
回复
是呀 #0一般都是做为字符串的终结符的...
你如果明确知道返回的长度的话 那么直接读相应长度的内存就是。。
Drate 2004-11-27
  • 打赏
  • 举报
回复
嗯,前几天我也碰上这个问题,其实用PCHAR跟用STRING是没有什么区别的,只是你在用的时候要注意了,注意不要把#0一块返回过来,你用一个StrPas函数就可以把它转换成为DELPHI的STRING了
YFLK 2004-11-27
  • 打赏
  • 举报
回复
pchar指向的字串是不受长度限制的,而且是以零做结尾的,当串中有“零”则不能保证串的后面没有数据。
zdq801104 2004-11-26
  • 打赏
  • 举报
回复
应该PCHAR 比STRING更加合适的呀
「已注销」 2004-11-26
  • 打赏
  • 举报
回复
string是字符数组,而pchar是零终止串
S1 := String(PChar(S1));
这样处理一下就可以安全的把pchar转换成string
「已注销」 2004-11-26
  • 打赏
  • 举报
回复
把返回值处理一下:
S1 := String (PChar (S1));
hdhhb 2004-11-26
  • 打赏
  • 举报
回复
delphi的string和windows即c中的Pchar类型是完全兼容的。
把你的成功的代码和出错的代码片断贴出来看一下!
BlueSoftEye 2004-11-26
  • 打赏
  • 举报
回复
你可以返回值设为String,注意在Uses 中加入 “ShareMem"
具体:
--------------------------------
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
--------------------------------


yinzhiw 2004-11-26
  • 打赏
  • 举报
回复
贴点代码看看
huiwww 2004-11-26
  • 打赏
  • 举报
回复
字符长到多少?
merkey2002 2004-11-26
  • 打赏
  • 举报
回复
不懂,帮顶~

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧