Q
qutwah
Unregistered / Unconfirmed
GUEST, unregistred user!
请各位富翁们帮帮看看.Var FS :TFileStream; sFile,sExeFile :String; MyUI :TUserData; FH:THandle; FindRes,LoadRes,hUpdateRes:HRSRC; ResSize: LongWord; LockResointer; UpdateRst :Boolean; //资源更新结果 Buf: array of byte; MS :TMemoryStream;begin OD.Filter :='Excute file(*.exe)|*.exe'; OD.FilterIndex :=0; if OD.Execute Then begin try sExeFile :=OD.FileName; FS :=TFileStream.Create(sExeFile,fmShareDenyNone); MyUI.ComputerName :=GetComputerName; MyUI.FormCaption :=UI.FormCaption; MyUI.StartUseDate :=Now; MyUI.LastUseDate :=Now; MyUI.ExeSize :=FS.Size; MyUI.MD5 :=MD5Print(MD5File(Trim(sExeFile))); FH:=LoadLibrary(PChar(sExeFile)); if FH>0 then try FindRes := FindResource(FH, 'UserData','MyFile'); if FindRes <> 0 then begin ResSize := SizeofResource(FH, FindRes); if ResSize>0 then begin LoadRes:=LoadResource(FH,FindRes); if LoadRes<>0 then begin LockRes :=LockResource(LoadRes); if LockRes<>nil then begin hUpdateRes := BeginUpdateResource(Pchar(sExeFile),False); UpdateRst :=UpdateResource(hUpdateRes,'MyFile','UserData',0,@NewUI,ResSize); EndUpdateResource(hUpdateRes,False); end; end; end; end; finally FreeLibrary(FH); end; finally FS.Free; end; if UpdateRst then begin FH:=LoadLibrary(PChar(sExeFile)); if FH>0 then try FindRes := FindResource(FH, 'UserData','MyFile'); if FindRes <> 0 then begin ResSize := SizeofResource(FH, FindRes); if ResSize>0 then begin LoadRes:=LoadResource(FH,FindRes); if LoadRes<>0 then begin LockRes :=LockResource(LoadRes); if LockRes<>nil then begin FillChar(MyUI,SizeOf(MyUI),#0); SetLength(Buf,ResSize); CopyMemory(@Buf, LockRes, ResSize); try MS :=TMemoryStream.Create; MS.Write(Buf[0],SizeOf(Buf)); MS.Size; MS.Seek(0,soFromBeginning); MS.SaveToFile('e:/a.dat'); finally MS.Free; end; //MyUI :=LockRes^; //showmessage(MyUI.MD5); end; end; end; end; finally FreeLibrary(FH); end; end; end; end;