M
miniapollo
Unregistered / Unconfirmed
GUEST, unregistred user!
最近写程序过程中,调用一个dll(用des算法写的一个字符串加密模块)时,程序运行并且结果也正确,只是在关闭程序时出现
“project demo.exe raised exception class EInvalidPointer with
message 'Invalid pointer operation'. Process stopped . Use step or run to continue”
“
源程序如下:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Button3: TButton;
Edit4: TEdit;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
procedure Enpkg(const contentchar;const Encryptedchar;const keychar);
procedure EncryptPswd(const contentchar;const Encryptedchar;const Keychar)
stdcall external 'des.dll';
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Skey,scontent,sencryptedchar;
indata:array [0..59] of char;
inkey:array [0..8] of char;
begin
getmem(skey,8);
getmem(scontent,60);
getmem(sencrypted,120);
//for skey;
fillchar(inkey,9,0);
strlcopy(inkey,Pchar(edit4.Text),length(edit4.Text));
strlcopy(skey,inkey,length(edit4.Text));
//for scontent;
fillchar(indata,60,0);
strlcopy(indata,Pchar(edit1.Text),length(edit1.Text));
strlcopy(scontent,indata,length(edit1.Text));
enpkg(scontent,sencrypted,skey);
edit2.Text:=sencrypted;
end;
procedure Enpkg(var contentchar;var Encryptedchar;const keychar);
var
Skey,scontent,sencryptedchar;
intest1:array [0..4095] of char
//输入包;
outtest:array [0..4095] of char
//输出包;
tihuan:array [0..8] of char
//8位输入中转;
tohuan:array [0..12] of char
//12位输出中转;
i,j,k,m,lengths:integer;
k1:string
//按每8位截取待加密字符串;
begin
skey:=key;
sencrypted:=Encrypted;
fillchar(intest1,4096,0);
//将待加密字符串copy to Array中;
strcopy(intest1,content);
fillchar(outtest,4096,0);
fillchar(tihuan,9,0);
fillchar(tohuan,13,0);
//按每8位计算待加密循环次数 j;
lengths:=length(content)+4;
if (lengths mod 8)=0 then
j:=lengths
else
j:=lengths+8-lengths mod 8;
j:=round(j/8);
// 加密过程;
for i:=0 to j do
begin
k1:='';
for k:=0 to 7 do
k1:=k1+intest1[i*8+k];
scontent:=Pchar(k1);
encryptpswd(scontent,sencrypted,skey);
strlcopy(tohuan,sencrypted,12);
for m:=0 to 11 do
outtest[i*12+m]:=tohuan[m];
end;
strcopy(encrypted,outtest);
end;
end.
请各位大侠帮忙会诊,多谢。
“project demo.exe raised exception class EInvalidPointer with
message 'Invalid pointer operation'. Process stopped . Use step or run to continue”
“
源程序如下:
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit3: TEdit;
Button3: TButton;
Edit4: TEdit;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
procedure Enpkg(const contentchar;const Encryptedchar;const keychar);
procedure EncryptPswd(const contentchar;const Encryptedchar;const Keychar)
stdcall external 'des.dll';
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Skey,scontent,sencryptedchar;
indata:array [0..59] of char;
inkey:array [0..8] of char;
begin
getmem(skey,8);
getmem(scontent,60);
getmem(sencrypted,120);
//for skey;
fillchar(inkey,9,0);
strlcopy(inkey,Pchar(edit4.Text),length(edit4.Text));
strlcopy(skey,inkey,length(edit4.Text));
//for scontent;
fillchar(indata,60,0);
strlcopy(indata,Pchar(edit1.Text),length(edit1.Text));
strlcopy(scontent,indata,length(edit1.Text));
enpkg(scontent,sencrypted,skey);
edit2.Text:=sencrypted;
end;
procedure Enpkg(var contentchar;var Encryptedchar;const keychar);
var
Skey,scontent,sencryptedchar;
intest1:array [0..4095] of char
//输入包;
outtest:array [0..4095] of char
//输出包;
tihuan:array [0..8] of char
//8位输入中转;
tohuan:array [0..12] of char
//12位输出中转;
i,j,k,m,lengths:integer;
k1:string
//按每8位截取待加密字符串;
begin
skey:=key;
sencrypted:=Encrypted;
fillchar(intest1,4096,0);
//将待加密字符串copy to Array中;
strcopy(intest1,content);
fillchar(outtest,4096,0);
fillchar(tihuan,9,0);
fillchar(tohuan,13,0);
//按每8位计算待加密循环次数 j;
lengths:=length(content)+4;
if (lengths mod 8)=0 then
j:=lengths
else
j:=lengths+8-lengths mod 8;
j:=round(j/8);
// 加密过程;
for i:=0 to j do
begin
k1:='';
for k:=0 to 7 do
k1:=k1+intest1[i*8+k];
scontent:=Pchar(k1);
encryptpswd(scontent,sencrypted,skey);
strlcopy(tohuan,sencrypted,12);
for m:=0 to 11 do
outtest[i*12+m]:=tohuan[m];
end;
strcopy(encrypted,outtest);
end;
end.
请各位大侠帮忙会诊,多谢。