我才通过编译的DLL<br>library _NewSize;<br><br>uses<br> SysUtils,<br> Windows,<br> Dialogs,<br> inifiles,<br> Classes,<br> UBackup in '../设置定时备份/UBackup.pas' {FrmBackup};<br><br>{$R *.res}<br>var<br> ini,Pini: tinifile;<br> TimerBackup, TimerSave, TimerOn: Cardinal; //定时器变量<br> H: hWnd; //PDS窗口句柄<br> TBackup,TSave: Integer;<br> //BHnd: Hwnd;<br> S,P,BackupPath,filename,sDir,aCaption: string; //文件路径<br> SaveExit: Pointer;<br> StartSave: Bool=False;<br> StartBackup: Bool=False;<br> SaveBool: Bool=False;<br> BackupBool: Bool=false;<br><br>procedure LibExit;<br>begin<br> // 库退出时的处理<br> KillTimer(0,TimerBackup);<br> KillTimer(0,TimerOn);<br> ExitProc := SaveExit; // 恢复退出链<br>end;<br><br>Function MCopyFile(var sourcefile:string; targetfile:string):boolean;<br>var<br> s,t:Tfilestream;<br>begin<br> MCopyFile:=True;<br> s:=Tfilestream.Create(sourcefile,fmopenread);<br> try<br> Try<br> t:=Tfilestream.Create(Targetfile,fmopenwrite or fmcreate);<br> try<br> t.CopyFrom(s,s.size);<br> finally<br> t.free;<br> end;<br> finally<br> s.free;<br> end;<br> except<br> MCopyFile:=False;<br> end;<br>end;<br><br>//提取字符串中指定子字符串后的字符串<br>function After(Str,S:string): string ;<br>var<br> f: Word;<br>begin<br> f:=pos(s,str);<br> if F=0 then<br> After:=''<br> else<br> After:=COPY(Str,F+1,length(str)-length(s));<br>end;<br><br>procedure Call_PicShow();stdcall;<br>Var<br> dllName,FuncName:string;<br> LibHandle:HWND;<br> DName:Function():bool;stdcall;<br>begin<br> dllName:='_NewRule.dll';<br> FuncName:='PicShow';<br> LibHandle:=LoadLibrary(pchar(dllName));<br> if LibHandle<32 then<br> begin<br> MessageBox(0,pchar('Not Found'+ dllName),'Error',0);<br> Exit;<br> end;<br> @DName:=GetProcAddress(LibHandle,pchar(FuncName));<br> if @DName=NIL then<br> begin<br> MessageBox(0,pchar('Not Found '+FuncName+' in'+ dllName),'Error',0);<br> FreeLibrary(LibHandle);<br> Exit;<br> end;<br> try<br> DName();<br> finally<br> FreeLibrary(LibHandle);<br> end;<br>end;<br><br>procedure Call_NewSize();stdcall;<br>Var<br> dllName,FuncName: string;<br> LibHandle:HWND;<br> DName:Function:bool;stdcall;<br>begin<br> dllName:='_NewRule.dll';<br> FuncName:='NewSize';<br> LibHandle:=LoadLibrary(pchar(dllName));<br> if LibHandle<32 then<br> begin<br> MessageBox(0,pchar('Not Found'+ DllName),'Error',0);<br> Exit;<br> end;<br> @DName:=GetProcAddress(LibHandle,pchar(FuncName));<br> if @DName=NIL then<br> begin<br> MessageBox(0,pchar('Not Found '+FuncName+' in '+ DllName),'Error',0);<br> FreeLibrary(LibHandle);<br> Exit;<br> end;<br> try<br> DName;<br> finally<br> FreeLibrary(LibHandle);<br> end;<br>end;<br><br>procedure Call_PicSearch();stdcall;<br>Var<br> dllName,FuncName: string;<br> LibHandle:HWND;<br> DName:Function:bool;stdcall;<br>begin<br> dllName:='_NewRule.dll';<br> FuncName:='PicSearch';<br> LibHandle:=LoadLibrary(pchar(dllName));<br> if LibHandle<32 then<br> begin<br> MessageBox(0,pchar('Not Found'+ DllName),'Error',0);<br> Exit;<br> end;<br> @DName:=GetProcAddress(LibHandle,pchar(FuncName));<br> if @DName=NIL then<br> begin<br> MessageBox(0,pchar('Not Found '+FuncName+' in '+ DllName),'Error',0);<br> FreeLibrary(LibHandle);<br> Exit;<br> end;<br> try<br> DName;<br> finally<br> FreeLibrary(LibHandle);<br> end;<br>end;<br><br>procedure Call_TajimaDGML();stdcall;<br>var<br> s: string;<br>begin<br> s:=ini.ReadString('Programs','TajimaDGML','E:/DGMLWin/bin/DG.exe');<br> WinExec(Pchar(s),5);<br>end;<br><br>procedure Call_BiaoZhunSize();StdCall;<br>Var<br> dllName,FuncName: string;<br> LibHandle:HWND;<br> DName:Function:bool;stdcall;<br>begin<br> dllName:='_JJGSize32.dll';<br> FuncName:='BiaoZhunCC';<br> LibHandle:=LoadLibrary(pchar(dllName));<br> if LibHandle<32 then<br> begin<br> MessageBox(0,pchar('Not Found'+ DllName),'Error',0);<br> Exit;<br> end;<br> @DName:=GetProcAddress(LibHandle,pchar(FuncName));<br> if @DName=NIL then<br> begin<br> MessageBox(0,pchar('Not Found '+FuncName+' in '+ DllName),'Error',0);<br> FreeLibrary(LibHandle);<br> Exit;<br> end;<br> try<br> DName;<br> finally<br> FreeLibrary(LibHandle);<br> end;<br>end;<br><br>procedure CallDll_BZCC();stdcall;<br>Var<br> dllName,FuncName: string;<br> LibHandle,fwnd:HWND;<br> DName:Function(AHandle:THandle):bool;stdcall;<br>begin<br> dllName:='_JJGSize32.dll';<br> FuncName:='ShowFrom';<br> fwnd:=findwindow('TMDIForm',nil);<br> LibHandle:=LoadLibrary(pchar(dllName));<br> if LibHandle<32 then<br> begin<br> MessageBox(0,pchar('Not Found'+ dllName),'Error',0);<br> Exit;<br> end;<br> @DName:=GetProcAddress(LibHandle,pchar(FuncName));<br> if @DName=NIL then<br> begin<br> MessageBox(0,pchar('Not Found '+FuncName+' in'+ dllName),'Error',0);<br> FreeLibrary(LibHandle);<br> Exit;<br> end;<br> try<br> if fwnd<>0 then<br> DName(fwnd);<br> finally<br> FreeLibrary(LibHandle);<br> end;<br>end;<br><br>procedure CallDll_E();Stdcall;<br>Var<br> dllName,FuncName: string;<br> LibHandle:HWND;<br> DName:Function:bool;stdcall;<br>begin<br> dllName:='_NewRule.dll';<br> FuncName:='ShowNarrate';<br> LibHandle:=LoadLibrary(pchar(dllName));<br> if LibHandle<32 then<br> begin<br> MessageBox(0,pchar('Not Found'+ DllName),'Error',0);<br> Exit;<br> end;<br> @DName:=GetProcAddress(LibHandle,pchar(FuncName));<br> if @DName=NIL then<br> begin<br> MessageBox(0,pchar('Not Found '+FuncName+' in '+ DllName),'Error',0);<br> FreeLibrary(LibHandle);<br> Exit;<br> end;<br> try<br> DName;<br> finally<br> FreeLibrary(LibHandle);<br> end;<br>end;<br><br>procedure CallDll_F();stdcall;<br>begin<br> ShowBackup;<br>end;<br><br>procedure Call_Capture();stdcall;<br>var<br> s:string;<br>begin<br> s:=ini.ReadString('Programs','Capture','');<br> s:=after(s,',');<br> WinExec(pchar(s),5);<br>end;<br><br>procedure Call_Order();stdcall;<br>var<br> s:string;<br>begin<br> s:=ini.ReadString('Programs','Order','');<br> s:=after(s,',');<br> WinExec(pchar(s),5);<br>end;<br><br>procedure Call_Layout();stdcall;<br>var<br> s:string;<br>begin<br> s:=ini.ReadString('Programs','LayoutMarker','');<br> s:=after(s,',');<br> WinExec(pchar(s),5);<br>end;<br><br>procedure Call_Plotter();stdcall;<br>var<br> s:string;<br>begin<br> s:=ini.ReadString('Programs','OutputManager','');<br> s:=after(s,',');<br> WinExec(pchar(s),5);<br>end;<br><br>procedure pTest;<br>Begin<br> StartBackup:=Pini.ReadBool('Program','chkBackup',False);<br> StartSave:=Pini.ReadBool('Program','chkSave',False);<br> if StartBackup=true then<br> begin<br> h:=findwindow('TMDIForm',nil);<br> if h<>0 then<br> begin<br> aCaption:=EIGetWinText(GetFocusedChildWindow(h));<br> filename:=after(aCaption,'>');<br> sDir:=before(aCaption,'-');<br> end;<br><br> if pos('>',aCaption)<>0 then<br> begin<br> P:=BackupPath+'/'+sDir+'/Pattern';<br> if not DirectoryExists(P) then<br> begin<br> if ForceDirectories(P) then //创建多级目录<br> forceDirectories(P);<br> end;<br> BackupBool:=true;<br> if StartSave=true then<br> SaveBool:=true;<br> end;<br> end;<br>End;<br><br>Procedure TBackupOn;<br>Begin<br> if BackupBool=true then<br> begin<br> s:=SJDir(ExpandFileName('_NewSize.dll'),2)+'/User/'+sDir+'/Pattern/'+filename;<br> //执行代码;<br> FileCopyFile(S,BackupPath+'/'+sDir+'/Pattern/'+filename);<br> end;<br>End;<br><br>exports<br>CallDll_BZCC,<br>Call_PicShow,<br>Call_NewSize,<br>Call_PicSearch,<br>Call_BiaoZhunSize,<br>CallDll_E,<br>CallDll_F,<br>Call_Capture,<br>Call_Order,<br>Call_Layout,<br>Call_TajimaDGML,<br>Call_Plotter;<br><br>begin<br> //... // 库加载处理<br> ini:=tinifile.Create(ExtractFilePath(Paramstr(0))+'Eastmark.ini');<br> Pini:=tinifile.Create(ExtractFilePath(Paramstr(0))+'Pds.ini');<br> TBackup:=Pini.ReadInteger('Program','BackupTimes',50000);//备份定时器时间<br> BackupPath:=Pini.ReadString('Program','BackupPath','F:/Gms/User');<br> TSave:=Pini.ReadInteger('Program','SaveTimes',50000); //保存定时器时间<br> TimerBackup:=SetTimer(0,0,TBackup*10000,@TBackupOn);<br> TimerOn:=SetTimer(0,0,500,@pTest);<br> ExitProc := @LibExit; //装入退出过程<br> SaveExit := ExitProc; //保存退出链<br>end.