compile another application to resource, then generate a execute file and start it,
this application modify the first application by update the resource. then start it,
then close self.
some code is below.
in first appliction
procedure TForm1.Button1Click(Sender: TObject);
var
lvi_ResHandle: THandle;
lvi_MemHandle: THandle;
lvp_ResPtr: PByte;
lvi_ResSize: integer;
lvs_ResFile: string;
lvi_ExtStart: integer;
lvo_binfile:file of byte;
FResourceType:string;
FileName:string;
begin
FResourceType:='exefile';
FileName:='test';
lvi_ExtStart := Pos('.', FileName);
if lvi_ExtStart = 0 then
lvi_ExtStart := Length(FileName)
else
dec(lvi_ExtStart);
lvs_ResFile := Copy(FileName, 1, lvi_ExtStart);
lvi_ResHandle := FindResource(hInstance, PChar(lvs_ResFile), PChar(FResourceType));
if lvi_ResHandle = 0 then
Exit;
try
lvi_MemHandle := LoadResource(hInstance, lvi_ResHandle);
lvp_ResPtr := LockResource(lvi_MemHandle);
lvi_ResSize := SizeOfResource(hInstance, lvi_ResHandle);
FreeResource(lvi_MemHandle);
assignfile(lvo_binfile,FileName);
rewrite(lvo_binfile);
blockwrite(lvo_binfile,lvp_ResPtr^,lvi_ResSize);
closefile(lvo_binfile);
finally
end;
end;
in the second one,
procedure TForm1.Button1Click(Sender: TObject);
var
ptr
ointer;
lvo_binfile:file of byte;
lvo_binfile2:file of byte;
reshandle:thandle;
lvi_ExtStart: integer;
lvs_ResFile:string;
lvo_content:tstrings;
FExeFileName:string;
FResourceType:string;
result:boolean;
begin
FExeFileName:='project1.exe';
FResourceType:='inifile';
lvs_ResFile:='profile.ini';
reshandle:=BeginUpdateResource(pchar(FExeFileName),TRUE);
assignfile(lvo_binfile,lvs_ResFile);
reset(lvo_binfile);
getmem(ptr,filesize(lvo_binfile));
blockread(lvo_binfile,ptr^,filesize(lvo_binfile));
UpdateResource(reshandle,pchar(FResourceType),'profile',0,ptr,filesize(lvo_binfile)) ;
showmessage(SysErrorMessage(GetLastError));
EndUpdateResource(reshandle,false);
freemem(ptr);
closefile(lvo_binfile);
end;