有.rc
文件,其中包含用于exe文件详细信息的版本,说明等。
如何获得在代码内使用的值?例如,要获取ProductName。
IDI_ICON1 ICON DISCARDABLE "abc-logo.ico" #if defined(UNDER_CE) #include <winbase.h> #else #include <winver.h> #endif VS_VERSION_INFO VERSIONINFO FILEVERSION 9, 9, 9, 9 PRODUCTVERSION 12, 01, 15, 1 FILEFLAGSMASK 0x3fL FILEFLAGS 0 FILEOS VOS_NT_WINDOWS32 FILETYPE VFT_APP FILESUBTYPE VFT2_UNKNOWN BEGIN BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x0404, 1200 END BLOCK "StringFileInfo" BEGIN BLOCK "040404b0" BEGIN VALUE "CompanyName", "Company A " VALUE "FileDescription", "Software A " VALUE "FileVersion", "1.0.0.0 " VALUE "InternalName", "SoftwareX " VALUE "LegalCopyright", "Copyright (C) Software Inc. All Rights Reserved " VALUE "OriginalFilename", "SoftwareA.exe " VALUE "ProductName", "Software A " VALUE "ProductVersion", "1.1.0.0 " END END END
需要使用GetFileVersionInfo()
和VerQueryValue()
函数
例如:
TCHAR FileName[MAX_PATH]; GetModuleFileName(NULL, FileName, MAX_PATH); DWORD Handle; DWORD Size = GetFileVersionInfoSize(FileName, &Handle); std::vector<BYTE> Data(Size); GetFileVersionInfo(FileName, Handle, Size, Data.data()); LPTSTR ProductName; UINT Len; VerQueryValue(Data.data(), TEXT("\StringFileInfo\040404b0\ProductName"), (LPVOID*) &ProductName, &Len); // use ProductName up to Len chars as needed... LPTSTR LegalCopyright; VerQueryValue(Data.data(), TEXT("\StringFileInfo\040404b0\LegalCopyright"), (LPVOID*) &LegalCopyright, &Len); // use LegalCopyright up to Len chars as needed...