views:

598

answers:

2

I was wanting to create a small tool in Delphi which can update the Delphi version information in another exe file. I know several existing utilities are out there for this but I need full programmatic control and would prefer no shelling out to the command line, etc.

After a web search I couldn't find any Delphi source code examples of modifying version information in an exe, could anyone provide some code or direction?

Thanks in advance for any assistance.

+7  A: 

I can't give a complete answer, but I can get you started. There is an article at DelphiDabbler.com that fills in how to get to the version information out of a file. GetFileVersionInfo is the Windows API to do that. To set it, I believe UpdateResource is the Windows API function you'll need to use. There is another article at CodeProject that covers this, using C, but it should give you a solid idea of what needs to be done.

Good luck!

Edit: I found some code on the Delphi newsgroups that might give you some more help:

// Credit to Michael Winter for this code!
Sz := GetLen;
GetMem(Data, Sz);
try
  GetData(Data, Sz);
  HFile := BeginUpdateResource(PChar(FileName), false);
  if HFile = 0 then
    RaiseLastWin32Error;
  DoDiscard := true;
  try
    if not UpdateResource(HFile, RT_VERSION, PChar(1), 0, Data, Sz) then
      RaiseLastWin32Error;
    DoDiscard := false;
  finally
    if not EndUpdateResource(HFile, DoDiscard) then
      RaiseLastWin32Error;
  end;
finally
  FreeMem(Data);
end;

It's just a snippet, and will require some work on your part, but that's the lion's share of the work!

Tim Sullivan
+3  A: 

There's also Colin Wilson's XN Resource Editor with source code which might help.

TOndrej