39 lines
946 B
C++
Raw Normal View History

2024-04-04 00:41:44 +08:00
2024-11-05 15:46:45 +08:00
DECLARE_API bool queryversion(const wchar_t *exe, WORD *_1, WORD *_2, WORD *_3, WORD *_4)
2024-04-04 00:41:44 +08:00
{
DWORD dwHandle;
DWORD dwSize = GetFileVersionInfoSizeW(exe, &dwHandle);
if (dwSize == 0)
{
return false;
}
std::vector<char> versionInfoBuffer(dwSize);
if (!GetFileVersionInfoW(exe, dwHandle, dwSize, versionInfoBuffer.data()))
{
return false;
}
VS_FIXEDFILEINFO *pFileInfo;
UINT fileInfoSize;
if (!VerQueryValueW(versionInfoBuffer.data(), L"\\", reinterpret_cast<LPVOID *>(&pFileInfo), &fileInfoSize))
{
return false;
}
DWORD ms = pFileInfo->dwFileVersionMS;
DWORD ls = pFileInfo->dwFileVersionLS;
WORD majorVersion = HIWORD(ms);
WORD minorVersion = LOWORD(ms);
WORD buildNumber = HIWORD(ls);
WORD revisionNumber = LOWORD(ls);
*_1 = majorVersion;
*_2 = minorVersion;
*_3 = buildNumber;
*_4 = revisionNumber;
return true;
}