c++将.rc中的版本转换为代码
c++ get version from .rc into code
可能重复:
如何在Visual C++中读取版本资源
在我的c++项目中,我添加了一个.rc文件,在那里我可以存储文件版本、可执行文件描述、版权等。
好的,我编译了,我转到explorer->文件属性,我看到了表单中的所有字段。
我的问题是:如果我需要从项目中读取自己的文件版本(例如显示为表单(,我该如何做到这一点?
感谢
Windows提供了一组API调用,用于从可执行文件中检索版本信息。下面的代码片段应该可以帮助您入门。
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;
}
在可执行文件上使用这些函数:
http://msdn.microsoft.com/en-us/library/ms646981%28v=VS.85%29.aspx
相关文章:
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在混合代码库中将C转换为C++时出现许多包含错误
- 为什么g++在未执行的代码处标记强制转换错误
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 16 位到 10 位转换代码说明
- 以下对二进制转换代码的小数如何工作
- 中缀到后缀表达式转换代码不起作用
- C++中的十进制到十六进制转换代码
- 这个后缀转换 C++ 代码的中缀有什么问题
- 如何优化 YUV 到 RGB 颜色转换代码
- Win32 键转换代码输出不需要的按键
- C++ NV12 到 RGB24 转换代码
- 转换代码以使用矢量
- C++货币转换代码
- 这段c++类型转换代码在做什么?
- 缓慢运行的方向转换代码
- 在c++中转换代码页
- 转换代码从SSE2到SSE4在C
- MATLAB到c++的行转换代码
- 如何编写可转换代码,32位/64位