Quote
"Frank Peelo" <fpe...@portablesolutions.com> wrote in message news:97ddbi$j3b$1@kermit.esat.net...
> "Jeff" <j...@profish.fsnet.co.uk> wrote in message
> news:976m5k$5c6$1@news5.svr.pol.co.uk...
> > Ok, this is a wierd request:
> > I want to write a program to modify a program i have written. In
> other
> > words, i would ship the main program with this modifyer program
> which could
> > subsequently be used to modify various settings in the main program.
> The
> > main program would then be modified semi-permenantly - it would
> remember
> > its settings even if it was moved to another computer, with no other
> files,
> > but could be edited again in the future.
> Maybe someone could post a reply about resource files in Windows
> programs. .DFM files are AIUI just fancy .RES files, and you can hold
> resources in .RES files as well - your program's icon, version numbers
> and other stuff. And you can have strings in resource files as well,
> using ResourceString (under "Resource String" in the help on my
> machine - not found under "ResourceString"). My understanding was that
> such resources are linked to the exe file but were not part of the
> program; they get read into the program at run-time. And you should be
> able to change them with a resource editor.
> Now, if a resource editor can change these strings, there must be a
> well-defined format for such resources in a .EXE file, regardless of
> what language the .EXE was written in. Part of the .EXE spec or
> something. You could have your program settings in ResourceString
> constants. Then your question becomes: how does one write a resource
> editor? And I don't know that; but at least, if the above is true, it
> must be possible, and maybe someone even has a component for it
> somewhere.
updateresource() to change a resource in an exe file
only works in NT not w98, so you have above 98 use that in your patcher
otherwise use something like the test stubs cutnpaste below, with better checks
be aware that it doesn't update the exe checksums, or bother with making itself
pretty for the exe
so will blow up anything that honours checksums or expects its own data at the end of a file
there are a lot better ways of doing what you want
to have an exe save its own data into its own executable is a little harder
// add data to end of target exe
// replace any existing data block and truncate to new length if previous was longer
procedure TForm1.appenddataClick(Sender: TObject);
var F:thandle;
var S:string;
var fpos:integer;
var ca:array[1..100] of char;
var count:integer;
var TS:Tstringlist;
begin
TS:=tstringlist.create;
F:=createfile('target.exe',Generic_READ or GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if F <> INVALID_HANDLE_VALUE then
begin
fpos:=setfilepointer(F,-100,0,FILE_END);
readfile(F,ca,100,cardinal(fpos),0);
for count := 100 downto 1 do
if strlcomp(@(ca[count]),pchar('exedata'),7)=0 then break;
if strlcomp(@(ca[count]),pchar('exedata'),7)=0 then
begin
fpos:=setfilepointer(F,-(100-count+1),0,FILE_END);
TS.settext(@(ca[count]));
memo1.lines.add('was registered to '+ TS.values['reguser']);
end
else
memo1.lines.add('no exedata found');
// data block starts with 'exedata' , ending with #0 and CR/LF seperation makes it easy to parse into a stringlist
S:='exedata'+#13#10+'reguser=nobody'#13#10+'pos1=1'+#13#10+'pos2=45'+#13#10#0;
strpcopy(@ca,S);
writefile(F,ca,length(S),cardinal(fpos),0);
fileclose(F);
end
else
memo1.lines.add('open file failure');
end;
// read the data at end of current exe
procedure TForm1.readmydataClick(Sender: TObject);
var F:thandle;
var fpos:integer;
var ca:array[1..100] of char;
var count:integer;
var TS:Tstringlist;
begin
TS:=tstringlist.create;
F:=createfile(pchar(paramstr(0)),Generic_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0);
if F <> INVALID_HANDLE_VALUE then
begin
fpos:=setfilepointer(F,-100,0,FILE_END);
readfile(F,ca,100,cardinal(fpos),0);
for count := 100 downto 1 do
if strlcomp(@(ca[count]),pchar('exedata'),7)=0 then break;
if strlcomp(@(ca[count]),pchar('exedata'),7)=0 then
begin
TS.settext(@(ca[count]));
memo1.lines.add('registered to '+ TS.values['reguser']);
end
else
memo1.lines.add('no exedata found');
fileclose(F);
end
else
memo1.lines.add('open file failure');
end;