Reputation: 43
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 .
Thanks John
Upvotes: 4
Views: 2179
Reputation: 6831
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.
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"
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.
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);
Upvotes: 5