黑客X档案官方论坛's Archiver

regedit 发表于 2008-7-18 16:32

VB 调用 Delphi写的DLL

用VB调用DELPHI写的DLL为什么不能返回字符串?
VB中的STRING好像是没有长度的限制,但是DELPHI中的String有长度的限制~
不能正确返回~请懂的朋友帮帮忙。

附件中的DEPHI中有两个函数,返回整数和返回字符串。
VB是调用DELPHI生成的DLL

regedit 发表于 2008-7-20 18:39

这个问题应该很难解决~因为在“X”论坛上放了几天了竟然没有一个人过问;
这个问题应该太简单了~因为大家都是看一下,感觉自己会,但是因为问题太简单,就不回答了——有失身份。

以上两种哪个正确呢?

shn7798 发表于 2008-7-20 18:49

在delphi中把dll的导出函数用stdcall协议试试看

shn7798 发表于 2008-7-20 19:02

[code]function Str1(const aa:integer):PChar;stdcall;
begin
result:=PChar(IntToStr(aa));
end;[/code]改成这样就好了...一半dll中传的是地址...用PChar,不要用string

regedit 发表于 2008-7-20 19:29

谢谢楼上的 但是改成这样就出错了 寻找原因[code]function Str1(const aa:integer):PChar;stdcall;
begin
result:=PChar('就是这样!');//也就是说pchar里面不能直接用字符串但是通过一个变量字符串传递就没有这样的错了,迷茫。
end;[/code]=============================
改成下面的就不会有错了
=============================[code]function Str1(const aa:integer):PChar;stdcall;
var s:string;
begin
s:='就是这样!';
result:=PChar(s); //  这样错误就消失了  求解
end;[/code]

dingzehao 发表于 2008-8-4 09:40

天书::23:: ::23:: ::23:: ::23::
先顶一下

页: [1]


Powered by Discuz! 6.1.0  © 2001-2007 Comsenz Inc.