急急急!(20分)

  • 主题发起人 主题发起人 ANDREWWUYOU
  • 开始时间 开始时间
A

ANDREWWUYOU

Unregistered / Unconfirmed
GUEST, unregistred user!
请高手指点 我把下面函数做成DLL文件要用时调用他但是每次用完关掉程序时或调用时出现问题:说该程序执行了非法操作即将关闭。如果仍有问题请与程序供应商联系.<br> library ymzpdll;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp; first unit in your library's USES clause AND your project's (select<br>&nbsp; Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp; functions that pass strings as parameters or function results. This<br>&nbsp; applies to all strings passed to and from your DLL--even those that<br>&nbsp; are nested in records and classes. ShareMem is the interface unit to<br>&nbsp; the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp; with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp; using PChar or ShortString parameters. }<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes;<br><br>&nbsp; <br>{$R *.res}<br>function encrypt(entext:string;key:string):string;stdcall;<br>//自定义的加密函数<br>var<br>x,i, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// count variables<br>sText,sPW: Integer; // size of Text, PW<br>Text,PW: &nbsp; PChar; &nbsp; // buffer for Text, PW<br>begin<br>&nbsp; sText:=Length(entext)+1;<br>&nbsp; sPW:=Length(key)+1;<br>&nbsp;GetMem(Text,sText);<br>&nbsp; GetMem(PW,sPW);<br>&nbsp; StrPCopy(Text,entext);<br>&nbsp; StrPCopy(PW,key);<br>&nbsp; x:=0; // initialize count<br>&nbsp; for i:=0 to sText-2 do<br>&nbsp; begin<br>&nbsp; &nbsp; Text:=Chr(Ord(Text)+Ord(PW[x]));<br>&nbsp; &nbsp; Inc(x);<br>&nbsp; &nbsp; if x=(sPW-1)then x:=0;<br>&nbsp; end;<br>&nbsp; result:=text;<br>&nbsp;// FreeMem(Text);<br>&nbsp;// FreeMem(PW);<br>end;<br><br>function decrypt(detext:string;key:string):string;stdcall; //自定义的解密函数<br>var<br>x,i, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// count variables<br>sText,sPW: Integer; // size of Text, PW<br>Text,PW: &nbsp; PChar; &nbsp; // buffer for Text, PW<br>begin<br>&nbsp; sText:=Length(detext)+1;<br>&nbsp; sPW:=Length(key)+1;<br>&nbsp; GetMem(Text,sText);<br>&nbsp; GetMem(PW,sPW);<br>&nbsp; StrPCopy(Text,detext);<br>&nbsp; StrPCopy(PW,key);<br>&nbsp; x:=0; // initialize count<br>&nbsp; for i:=0 to sText-2 do<br>&nbsp; begin<br>&nbsp; &nbsp; Text:=Chr(Ord(Text)-Ord(PW[x]));<br>&nbsp; &nbsp; Inc(x);<br>&nbsp; &nbsp; if x=(sPW-1)then x:=0;<br>&nbsp; end;<br>&nbsp; result:=text;<br>&nbsp;FreeMem(Text);<br>&nbsp; FreeMem(PW);<br>end;<br>exports<br>encrypt,decrypt;<br><br><br>begin<br>end.<br>
 
把下面两行的注释去掉<br>&nbsp;// FreeMem(Text);<br>&nbsp;// FreeMem(PW);<br><br>
 
XUHAO1你那方法我用过不行
 
帮你提前一下
 
后退
顶部