<分区>
Possible Duplicate:
How do I read from a version resource in Visual C++
在我的 C++ 项目中,我添加了一个 .rc 文件,我可以在其中存储文件版本、可执行文件描述、版权等。
没问题,我编译,我转到资源管理器 -> 文件属性,我看到了表单中的所有字段。
我的问题是:如果我需要从项目中读取自己的文件版本(例如显示为表格),我该怎么做?
谢谢
标签 c++ versioninfo
<分区>
Possible Duplicate:
How do I read from a version resource in Visual C++
在我的 C++ 项目中,我添加了一个 .rc 文件,我可以在其中存储文件版本、可执行文件描述、版权等。
没问题,我编译,我转到资源管理器 -> 文件属性,我看到了表单中的所有字段。
我的问题是:如果我需要从项目中读取自己的文件版本(例如显示为表格),我该怎么做?
谢谢
最佳答案
Windows 提供了一组API calls for retrieving the version information来自可执行文件。以下代码片段应该可以帮助您入门。
bool GetVersionInfo(
LPCTSTR filename,
int &major,
int &minor,
int &build,
int &revision)
{
DWORD verBufferSize;
char verBuffer[2048];
// Get the size of the version info block in the file
verBufferSize = GetFileVersionInfoSize(filename, NULL);
if(verBufferSize > 0 && verBufferSize <= sizeof(verBuffer))
{
// get the version block from the file
if(TRUE == GetFileVersionInfo(filename, NULL, verBufferSize, verBuffer))
{
UINT length;
VS_FIXEDFILEINFO *verInfo = NULL;
// Query the version information for neutral language
if(TRUE == VerQueryValue(
verBuffer,
_T("\\"),
reinterpret_cast<LPVOID*>(&verInfo),
&length))
{
// Pull the version values.
major = HIWORD(verInfo->dwProductVersionMS);
minor = LOWORD(verInfo->dwProductVersionMS);
build = HIWORD(verInfo->dwProductVersionLS);
revision = LOWORD(verInfo->dwProductVersionLS);
return true;
}
}
}
return false;
}
关于c++从.rc获取版本到代码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6763262/