从Delphi PC应用程序获取compact framework exe的版本号(Get version number of compact framework exe from Delphi PC application)

我有一个为Compact Framework编译的应用程序,我需要找到使用Delphi 2006的版本号。我使用下面的代码。

function VersionNumber(ExeFile: string): string; var Size: Longint; Dummy: Cardinal; Buffer: Pointer; FileInfo: Pointer; begin Size := GetFileVersionInfoSize(PChar(ExeFile), Dummy); GetMem(Buffer, Size); if (GetFileVersionInfo(PChar(ExeFile), Dummy, Size, Buffer)) then begin //VerQueryValue(Buffer, '\\', FileInfo, Dummy); //with PVSFixedFileInfo(FileInfo)^ do //Result := IntToStr(dwFileVersionMS div $10000) + '.' + // IntToStr(dwFileVersionMS mod $10000) + '.' + // IntToStr(dwFileVersionLS div $10000) + ' (' + // IntToStr(dwFileVersionLS mod $10000) + ')'; end else begin Result := 'No version info available.'; end; FreeMem(Buffer, Size); end;

如果我使用Windows 7查看文件详细信息,我也看不到版本号,所以我无法从Delphi中获取它也就不足为奇了。

只是有机会有人知道获得版本号的方法,将非常感谢。

UPDATE

这段代码是十多年前由前工作人员编写的。 到目前为止,它运行良好,但从未尝试过为Compact Framework编译的可执行文件。

GetFileVersionInfo函数返回false,因此我收到“没有可用的版本信息”。 结果。

I have an application compiled for Compact Framework which I need to find the version number for using Delphi 2006. I am using the code below.

function VersionNumber(ExeFile: string): string; var Size: Longint; Dummy: Cardinal; Buffer: Pointer; FileInfo: Pointer; begin Size := GetFileVersionInfoSize(PChar(ExeFile), Dummy); GetMem(Buffer, Size); if (GetFileVersionInfo(PChar(ExeFile), Dummy, Size, Buffer)) then begin //VerQueryValue(Buffer, '\\', FileInfo, Dummy); //with PVSFixedFileInfo(FileInfo)^ do //Result := IntToStr(dwFileVersionMS div $10000) + '.' + // IntToStr(dwFileVersionMS mod $10000) + '.' + // IntToStr(dwFileVersionLS div $10000) + ' (' + // IntToStr(dwFileVersionLS mod $10000) + ')'; end else begin Result := 'No version info available.'; end; FreeMem(Buffer, Size); end;

If I view the file details using Windows 7 I cannot see the version number there either, so it's not surprising that I cannot get it from Delphi.

Just on the off chance someone knows a way to get the version number it would be greatly appreciated.

UPDATE

This code was written more then a decade ago by an ex staff member. Up until now, it has worked fine, but has never been tried on an executable compiled for Compact Framework.

The GetFileVersionInfo function is returning false, so I am getting 'No version info available.' result.

最满意答案

CF没有将C / C ++ FileVersionInfo放入exe或DLL文件中。 AssemblyInfo与您使用代码示例查找的FileVersionInfo资源不同。

ctacke在http://blog.opennetcf.com/2014/01/03/howto-add-the-win32-file-version-to-your-net-compact-framework-assemblies/上发表了一篇有用的文章。可以通过.NET程序集(Compact Framework 3.5 / VS2008)中缺少的版本信息找到,已经发布了什么是graymatter。

CF does not put C/C++ FileVersionInfo into exe or DLL files. The AssemblyInfo is something different from the FileVersionInfo resource you are looking for with your code sample.

ctacke has a usefull post about this at http://blog.opennetcf.com/2014/01/03/howto-add-the-win32-file-version-to-your-net-compact-framework-assemblies/ which can be found via Version information missing from .NET assembly (Compact Framework 3.5/VS2008), what graymatter already posted.

更多推荐