在DLL中写函数
function setpw(pstr:string):string;stdcall;
var
i:integer;
x:integer;
n:integer;
begin
x:=length(pstr);
if x<>0 then
begin
for i:=1 to x do
begin
n:=ord(pstr[i])+28;
if n>128 then
n:=n-128;
result:=result+chr(n);
end;
end;
end;
在程序中调用:
function setpw(pstr:string):string;stdcall;External'password.dll'
procedure ceshi();
begin
a:=setpw(b);
end;
产生错误:Invalid Pointer operation
经测试:当b的长度n=0或者2,3的时候不会产生错误,其他的时候产生错误。
望高手指教
function setpw(pstr:string):string;stdcall;
var
i:integer;
x:integer;
n:integer;
begin
x:=length(pstr);
if x<>0 then
begin
for i:=1 to x do
begin
n:=ord(pstr[i])+28;
if n>128 then
n:=n-128;
result:=result+chr(n);
end;
end;
end;
在程序中调用:
function setpw(pstr:string):string;stdcall;External'password.dll'
procedure ceshi();
begin
a:=setpw(b);
end;
产生错误:Invalid Pointer operation
经测试:当b的长度n=0或者2,3的时候不会产生错误,其他的时候产生错误。
望高手指教
最好用pchar,而不要用string
function setpw(pstr:pchar):pchar;export;
var
i:integer;
x:integer;
n:integer;
result1:string;
begin
x:=length(pstr);
result:='';
if x<>0 then
begin
for i:=1 to x do
begin
n:=ord(pstr[i])+28;
if n>128 then
n:=n-128;
result1:=result1+chr(n);
end;
end;
result:=pchar(result1);
end;function setpw(pstr:pchar):pchar;External'project1.dll'procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=setpw(pchar('assdfsdf'));
end;
调试通过,嘿嘿,可以揭贴了吧
要在两个文件中都
uses ShareMem;
又学到了新东西~