C++ 项目中文件版本中的自定义字段 [英] Custom field in file version in C++ project

查看:18
本文介绍了C++ 项目中文件版本中的自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨有没有办法在 C++ 项目的文件版本中创建自定义字段.这样我们就可以看到这些字段以及文件版本、公司名称等.我想创建这样的字段修订版 = 1000定制 = OEM1.

Hi is there a way to create a custom field in the file version for a C++ project. So that we can see these fields along with file version, company name, etc. I would like to create fields like revision = 1000 Customization = OEM1 .

谢谢约翰

推荐答案

您可以向 .rc 文件中的版本信息添加额外的字段.您不能添加数字字段,但可以添加本地化的字符串字段.我从未尝试过使用 GUI 来执行此操作,但我知道您可以通过直接更改文件来实现.

You can add extra fields to the version information in your .rc file. You can't add numeric fields, but you can add localized string fields. I have never tried to do this with the GUI, but I know you can do it by changing the file directly.

在 Visual C++ 中,右键单击您的 .rc 文件,然后单击查看代码".在其中的某个地方,您会找到以以下内容开头的部分:

In Visual C++, right click on your .rc file and click "View Code." Somewhere in there, you will find a section that starts with:

BLOCK "StringFileInfo"

那个块可能只有一个子块:

That block probably only has one sub-block:

BLOCK "0409904b0"

那个数字是 en_us 的语言环境描述符的数字版本.此块包含几个 VALUE 条目,例如:

That number is the numeric version of the locale descriptor for en_us. This block contains several VALUE entries such as:

VALUE "FileVersion", "1, 0, 0, 0"
VALUE "OriginalFilename", "MyProjectName"

您可以向此部分添加任何您想要的字段,它会显示在可执行文件的属性对话框的版本选项卡上.

You can add any field you want to this section and it will show up on the version tab of the properties dialog for the executable.

如果您需要能够在运行时读取这些值,您可以像这样使用 GetFileVersionInfo:

If you need to be able to read these values at runtime, you can use GetFileVersionInfo like this:

wchar_t myModululeName[MAX_PATH];
GetModuleFileName(NULL,myModuleName,MAX_PATH);

DWORD dummy;
DWORD versionSize=GetFileVersionInfoSize(myModuleName,&dummy);

//I don't remember why I added extra space to these
void * versionInfo=malloc(versionSize+10);
GetFileVersionInfo(myModuleName,0,versionSize+1,versionInfo);

//This part is optional
//The VS_FIXEDFILEINFO contains information from the non-localized parts of
//the "StringFileInfo" block in the .rc file
VS_FIXEDFILEINFO * fixedFileInfo;
UINT fixedFileSize;
VerQueryValue(versionInfo,L"\\",(void **)(&fixedFileInfo),&fixedFileSize);

//This will retrieve the local codes that are defined in the StringFileInfo block
WORD * translationTable;
UINT translationSize;
VerQueryValue(verionInfo,L"\\VarFileInfo\\Translation",(void **)(&translationTable),&translationTableSize);

//This always uses the first locale, you could examine translationTable
//if you need to for other codes
wchar_t mySpecialQuery[128];
sprintf_s(mySpecialQuery,L"\\StringFileInfo\\%04x%04x\\MySpecialVersionInfo",translationTable[0],translationTable[1]);

wchar_t * mySpecialValue;
UINT mySpecialValueSize;
VerQueryValue(versionInfo,mySpecialQuery,(void **)(&mySpecialValue),&mySpecialValueSize);

//you can now do whatever you need to do with mySpecialValue, including using _wtoi()
//and query for more values

free(versionInfo);

这篇关于C++ 项目中文件版本中的自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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