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}begin
end.D2009中 用以下两个调用报错:function EnCode(Str, Key:String):String;stdcall;external 'Code.dll' ;
function DeCode(Str, Key:String):String;stdcall;external 'Code.dll' ;
如何解决?
光 引用时候变成
function EnCode(Str, Key:AnsiString):AnsiString;stdcall;external 'Code.dll' ;
function DeCode(Str, Key:AnsiString):AnsiString;stdcall;external 'Code.dll'
不行的。
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}begin
end.D2009中 用以下两个调用报错:function EnCode(Str, Key:String):String;stdcall;external 'Code.dll' ;
function DeCode(Str, Key:String):String;stdcall;external 'Code.dll' ;
如何解决?
光 引用时候变成
function EnCode(Str, Key:AnsiString):AnsiString;stdcall;external 'Code.dll' ;
function DeCode(Str, Key:AnsiString):AnsiString;stdcall;external 'Code.dll'
不行的。
解决方案 »
- wsprintf函数使用时,delphi中有问题,帮帮我
- 求教,我想用创建一个stringGrid 的控件数组,怎样定义和创建呀?请大侠帮帮忙。
- Delphi中如何多线程操作数据库中的数据表
- 如何将图片文件插入到EXECL文件中的某一个Cells中?急.....
- 谁有Rose2002序列码?有大奖!
- 请教DELPHI编程实现:从EXCEL中复制内容拷贝到其它应用程序的窗口中。
- 快来抢分,如何获得Listview当前被选择的纪录的每个字段的值
- 刚学用ole 不太会~!请教~!在线等啊~!!!
- jiaorg(jiaorg)请进:有关于代理服务器程序的问题请教
- DELPHI版的大虾,小虾,本人在这里向你们问好了!
- delphi2009的数据类型转换和Deiphi以前版本的有什么差异?比如PChar
- 串口通信的队列处理
function EnCode(Str,Key:String):String;stdcall;
begin
result:=EncryptString(Str, Key);
end; 因为EncryptString是aes单元的固定函数, 参数和result都是string的,没法变,dll函数应该怎么定义呢?
那比如 dll 中
function EnCode(Str,Key:pchar):pchar;stdcall;
一定可以的,目前我寫的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变成了: ,edt3解密不对 这又是啥原因呢?
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}begin
end.
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' ;
加解密都不报错,但也是只能对第一个字符进行加解密。
vRetStr : Array[0..255-1] of AnsiChar;
vEncryptStr : String; vEncryptStr := 'test';
strpcopy(vRetStr ,vEncryptStr); 再返回。