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