D7写的Dll,D2009如何调用呢?(35)

H

himoo

Unregistered / Unconfirmed
GUEST, unregistred user!
D7写的Dll,D2009如何调用呢?dll 代码是:library Code;uses SysUtils,AES, Classes;function EnCode(Str,Key:String):String;stdcall;begin result:=EncryptString(Str, Key);end;function DeCode(Str,Key:String):String;stdcall;begin result:=DecryptString(Str, Key);end
exports Encode, DeCode;{$R *.res}beginend.D2009中 用以下两个调用报错:function EnCode(Str, Key:String):String;stdcall;external 'Code.dll' ;function DeCode(Str, Key:String):String;stdcall;external 'Code.dll' ;如何解决?
 

【清风】

Unregistered / Unconfirmed
GUEST, unregistred user!
2009 和 D7 中的数据类型好像不一样了,你要看看两边数据类型的差别,在D7中的STRING在2009中是什么类型,具体调用的方法我觉得应该是一样的。
 

关门放狗

Unregistered / Unconfirmed
GUEST, unregistred user!
别用STRING类型。
 
H

happycyp

Unregistered / Unconfirmed
GUEST, unregistred user!
2009中这样调用。function EnCode(Str, Key:AnsiString):AnsiString;stdcall;external 'Code.dll' ;function DeCode(Str, Key:AnsiString):AnsiString;stdcall;external 'Code.dll'
 

鳄鱼先生

Unregistered / Unconfirmed
GUEST, unregistred user!
最好用PChar
 
H

himoo

Unregistered / Unconfirmed
GUEST, unregistred user!
happycyp, AnsiString 不行哦,报错依旧。鳄鱼先生, pchar应该怎么写?
 

草原骏马

Unregistered / Unconfirmed
GUEST, unregistred user!
function EnCode(const Str, Key:pChar):pChar;stdcall;external 'Code.dll' ;function DeCode(const Str, Key:pChar):pChar;stdcall;external 'Code.dll'
 
H

himoo

Unregistered / Unconfirmed
GUEST, unregistred user!
但是在Dll 中 function EnCode(Str,Key:String):String;stdcall
这样定义的,不会引起错误么?
 
H

himoo

Unregistered / Unconfirmed
GUEST, unregistred user!
dll中都变成pchar了:function EnCode(Str,Key:pchar):pchar;stdcall;begin result:=pchar(EncryptString(Str, Key));end;function DeCode(Str,Key:pchar):pchar;stdcall;begin result:=PChar(DecryptString(Str, Key));end;D7 中 主程序写function EnCode(Str, Key:pchar):pchar;stdcall;external 'Code.dll' ;function DeCode(Str, Key:pchar):pchar;stdcall;external 'Code.dll' ;begin edt2.Text:=EnCode(pchar(edt1.Text), '123')
edt3.Text:=DeCode(pchar(edt2.Text), '123');end;没有问题,都正确。但是主程序代码挪到d2009中编译,也能运行,不过edt2.text变成了:㄰㄰㄰㄰㄰㄰㄰㄰㄰㄰㄰&#12592
,edt3解密不对。。。 这又是啥原因呢?
 

枝上柳绵

Unregistered / Unconfirmed
GUEST, unregistred user!
没用过d2009,不过听说,在2009里pchar =pwidechar(不知对不对)在d7里,pchar=pansichar我的意思是,你把他们搞统一了,比如在d2009 里 function EnCode(const Str, Key:pansiChar):pansiChar;stdcall;external 'Code.dll' ;function DeCode(const Str, Key:pansiChar):pansiChar;stdcall;external 'Code.dll'仅供参考...
 

地质灾害

Unregistered / Unconfirmed
GUEST, unregistred user!
C

cst_zf

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL是语言无关的,所以接口里没有string类型因此最好改用pansichar但是要注意内存申请和释放的问题如果实在想用string的话,使用sharemem单元
 
H

himoo

Unregistered / Unconfirmed
GUEST, unregistred user!
根据以上几位的意见dll改成了library Code;uses SysUtils,AES, Classes;function EnCode(Str,Key:pansichar):pansichar;stdcall;begin result:=pansichar(EncryptString(Str, Key));end;function DeCode(Str,Key:pansichar):pansichar;stdcall;begin result:=pansichar(DecryptString(Str, Key));end;exports Encode, DeCode;{$R *.res}beginend.D2009中改成了function EnCode(Str, Key:pansiChar):pansiChar;stdcall;external 'Code.dll' ;function DeCode(Str, Key:pansiChar):pansiChar;stdcall;external 'Code.dll' ;此时不管加密的是什么字符,只能对第一个字节加密,如加密123,结果是对1的加密结果。而解密就会报错的。改成function EnCode(Str, Key:pwidechar):pwidechar;stdcall;external 'Code.dll' ;function DeCode(Str, Key:pwidechar):pwidechar;stdcall;external 'Code.dll' ;加解密都不报错,但也是只能对第一个字符进行加解密。
 

地质灾害

Unregistered / Unconfirmed
GUEST, unregistred user!
改声明有毛用 重要的是EncryptString和DecryptString怎么写的。
 
B

bsense

Unregistered / Unconfirmed
GUEST, unregistred user!
DLL 要通用 自然用 pchar ,最好是 pbyte 没有问题 ,getmem 由调用者取内存
 
S

siaosa

Unregistered / Unconfirmed
GUEST, unregistred user!
不同语言之间使用互调DLL, 必须符合DLL调用规范,不能用STRING
 

Similar threads

I
回复
0
查看
429
import
I
I
回复
0
查看
728
import
I
I
回复
0
查看
958
import
I
I
回复
0
查看
781
import
I
顶部