利用DLL在程序是实现文件拷贝
点击次数:53 次 发布日期:2008-11-09 08:37:41 作者:源代码网
|
源代码网推荐 源代码网推荐 在所开以的应用软件中,有时我们对某些文件进行拷贝(如对数据库进行备份、制作 源代码网推荐 安装程序),但是常用的一些语言却没有提供可直接进行文件拷贝的过程或函数。为此 源代码网推荐 ,我曾利用Delphi编制了可提供文件拷贝过程的动态连接库Copy.dll,其输出过程为 源代码网推荐 CopyFile。由于DLL具有简化编程、运行速度快等诸多优点,且不受编程语言的限制, 源代码网推荐 用Delphi编写的Copf.dll同样被VB、VC等面向对象语言进行静态或动态调用,人而方便 源代码网推荐 地在程序中实现文件拷贝。 源代码网推荐 源代码网推荐 附源程序如下: 源代码网推荐 library copf; 源代码网推荐 uses 源代码网推荐 SysUntils,Classes; 源代码网推荐 procedure copyfile(Sfname.Dfname:string):far;export;//带路径的文件名; 源代码网推荐 Var 源代码网推荐 Sourcef,Destinef:file; 源代码网推荐 NumRead,NumWritten:Integer; 源代码网推荐 Buf:array[1..4096] of char;//定义缓冲区; 源代码网推荐 Begin 源代码网推荐 AssignFile(Sourcef,dfname); 源代码网推荐 Reset(Sourcef,1); 源代码网推荐 AssignFile(Destinef,1); 源代码网推荐 Rewrite(Destinef,1); 源代码网推荐 Repeat 源代码网推荐 BlockRead(Sourcef,Buf,SizeOf(Buf),Numread);//读源文件 源代码网推荐 BlockWrite(destinef,buf,NumRead,NumWritten);//写目标文件; 源代码网推荐 Until (Numread=0) or (Numwritten<>numread); 源代码网推荐 closeFile(soucef); 源代码网推荐 Closefile(destinef); 源代码网推荐 end; 源代码网推荐 Esports 源代码网推荐 copyfile;//输出过程; 源代码网推荐 end; 源代码网推荐 以上源程序编译后便生成Copf.dll 源代码网推荐 现就静态调用举例: 源代码网推荐 unit Name; 源代码网推荐 interface 源代码网推荐 uses 源代码网推荐 Windows...; 源代码网推荐 Type 源代码网推荐 Tzcform=class(Tform) 源代码网推荐 ... 源代码网推荐 end; 源代码网推荐 var 源代码网推荐 Form1:Tform1; 源代码网推荐 implementation 源代码网推荐 Procedure copyfile(Sfname,dfname:string);far;external"c:copf";//DLL路径名; 源代码网推荐 {$R *.DFM} 源代码网推荐 Procedure Tform1.CopyButtonclick(sender:tobject); 源代码网推荐 Begin 源代码网推荐 ... 源代码网推荐 if fileesist(sfname)//如果源文件; 源代码网推荐 then copyfile(sfname,dfname); 源代码网推荐 ... 源代码网推荐 end; 源代码网推荐 源代码网供稿. |
