使用Delphi来修改另一个delphi程序的版本信息 [英] Using Delphi to modify the version information of another delphi program

查看:666
本文介绍了使用Delphi来修改另一个delphi程序的版本信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Delphi中创建一个小工具,可以在另一个exe文件中更新Delphi版本信息。我知道几个现有的实用程序在这里,但我需要完整的程序化控制,而不是炮击到命令行等。

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.

网页搜索后,我couldn没有找到任何修改版本信息的Delphi源代码示例,任何人都可以提供一些代码或方向?

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?

推荐答案

不能给出一个完整的答案,但我可以让你开始。 DelphiDabbler.com 上的文章填写了如何获取版本信息一个文件。 GetFileVersionInfo 是Windows API。要设置它,我相信 UpdateResource 是您需要使用的Windows API函数。使用C, CodeProject 中的另一篇文章涵盖了这一点,但应该给你一个牢固的想法,需要做什么。

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.

祝你好运!

编辑:我发现一些Delphi新闻组中的代码可能会为您提供更多帮助:

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!

这篇关于使用Delphi来修改另一个delphi程序的版本信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆