从 RC 文件访问字符串?
Accessing a string from the RC file?
我有这个 .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[=10=]"
VALUE "FileDescription", "Software A[=10=]"
VALUE "FileVersion", "1.0.0.0[=10=]"
VALUE "InternalName", "SoftwareX[=10=]"
VALUE "LegalCopyright", "Copyright (C) Software Inc. All Rights Reserved[=10=]"
VALUE "OriginalFilename", "SoftwareA.exe[=10=]"
VALUE "ProductName", "Software A[=10=]"
VALUE "ProductVersion", "1.1.0.0[=10=]"
END
END
END
使用GetFileVersionInfo()
and VerQueryValue()
函数,例如:
TCHAR FileName[MAX_PATH];
GetModuleFileName(NULL, FileName, MAX_PATH);
DWORD Handle;
DWORD Size = GetFileVersionInfoSize(FileName, &Handle);
if (Size == 0)
{
// error handling ...
}
std::vector<BYTE> VersionData(Size);
if (!GetFileVersionInfo(FileName, Handle, Size, VersionData.data()))
{
// error handling ...
}
LPTSTR Value;
UINT ValueLen;
if (VerQueryValue(VersionData.data(), TEXT("\StringFileInfo\040404b0\ProductName"), (LPVOID*) &Value, &ValueLen))
{
// use Value up to ValueLen chars as needed...
}
else
{
// error handling ...
}
if (VerQueryValue(VersionData.data(), TEXT("\StringFileInfo\040404b0\LegalCopyright"), (LPVOID*) &Value, &ValueLen))
{
// use Value up to ValueLen chars as needed...
}
else
{
// error handling ...
}
我有这个 .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[=10=]"
VALUE "FileDescription", "Software A[=10=]"
VALUE "FileVersion", "1.0.0.0[=10=]"
VALUE "InternalName", "SoftwareX[=10=]"
VALUE "LegalCopyright", "Copyright (C) Software Inc. All Rights Reserved[=10=]"
VALUE "OriginalFilename", "SoftwareA.exe[=10=]"
VALUE "ProductName", "Software A[=10=]"
VALUE "ProductVersion", "1.1.0.0[=10=]"
END
END
END
使用GetFileVersionInfo()
and VerQueryValue()
函数,例如:
TCHAR FileName[MAX_PATH];
GetModuleFileName(NULL, FileName, MAX_PATH);
DWORD Handle;
DWORD Size = GetFileVersionInfoSize(FileName, &Handle);
if (Size == 0)
{
// error handling ...
}
std::vector<BYTE> VersionData(Size);
if (!GetFileVersionInfo(FileName, Handle, Size, VersionData.data()))
{
// error handling ...
}
LPTSTR Value;
UINT ValueLen;
if (VerQueryValue(VersionData.data(), TEXT("\StringFileInfo\040404b0\ProductName"), (LPVOID*) &Value, &ValueLen))
{
// use Value up to ValueLen chars as needed...
}
else
{
// error handling ...
}
if (VerQueryValue(VersionData.data(), TEXT("\StringFileInfo\040404b0\LegalCopyright"), (LPVOID*) &Value, &ValueLen))
{
// use Value up to ValueLen chars as needed...
}
else
{
// error handling ...
}