#include <iostream>
#include <windows.h>
#include <string>
#include <vector>
#include <tlhelp32.h>
#include <Shlwapi.h>
#pragma comment(lib,"Version.lib")
#include <tchar.h>
using std::wstring;
int main()
{
std::cout << "Hello World!\n";
// get the filename of the executable containing the version resource
TCHAR szFilename[MAX_PATH + 1] = { };
if (GetModuleFileName(NULL, szFilename, MAX_PATH) == 0)
{
return -1;
}
//lstrcpy(szFilename, L"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe");
// allocate a block of memory for the version info
DWORD dwHandle;
DWORD dwSize = GetFileVersionInfoSize(szFilename, &dwHandle);
if (dwSize == 0)
{
return -1;
}
BYTE* pbVerBlock = new BYTE[dwSize];
// load the version info
if (!GetFileVersionInfo(szFilename, NULL, dwSize, (LPVOID)pbVerBlock))
{
return -1;
}
LPVOID lpBuffer;
UINT uLen;
if (!VerQueryValue(pbVerBlock, TEXT("\\"), &lpBuffer, &uLen)) {
return -1;
}
VS_FIXEDFILEINFO* lpFileInfo = (VS_FIXEDFILEINFO*)lpBuffer;
WORD nVer[4];
nVer[0] = HIWORD(lpFileInfo->dwProductVersionMS);
nVer[1] = LOWORD(lpFileInfo->dwProductVersionMS);
nVer[2] = HIWORD(lpFileInfo->dwProductVersionLS);
nVer[3] = LOWORD(lpFileInfo->dwProductVersionLS);
delete[]pbVerBlock;
return 0;
}
如何查看当前进程的版本号
最新推荐文章于 2025-05-14 22:27:35 发布