版本号 – 青春部落,流年似水 http://www.youthtribe.com 青春是一场远行,总记不起来时的路。 Thu, 25 Oct 2018 08:13:25 +0000 zh-CN hourly 1 https://wordpress.org/?v=6.1.7 版本号 – 青春部落,流年似水 http://www.youthtribe.com/archives/1739 http://www.youthtribe.com/archives/1739#respond Tue, 25 Sep 2018 10:47:50 +0000 http://www.youthtribe.com/?p=1739 首先工程需要引用 Version.lib,这个库。
项目》属性页》配置属性》链接器》输入》附加依赖项
debug和release都要添加。

CString GetSoftwareVersion()
{

	TCHAR szFullPath[MAX_PATH];
	DWORD dwVerInfoSize = 0;
	DWORD dwVerHnd;
	VS_FIXEDFILEINFO * pFileInfo;

	::GetModuleFileName(NULL, szFullPath, sizeof(szFullPath));
	dwVerInfoSize = ::GetFileVersionInfoSize(szFullPath, &dwVerHnd);
	if (dwVerInfoSize)
	{
		// If we were able to get the information, process it:
		HANDLE  hMem;
		LPVOID  lpvMem;
		unsigned int uInfoSize = 0;

		hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
		lpvMem = GlobalLock(hMem);
		GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);

		::VerQueryValue(lpvMem, (LPTSTR)_T("\\"), (void**)&pFileInfo, &uInfoSize);

		WORD m_nProdVersion[4];

		// Product version from the FILEVERSION of the version info resource 
		m_nProdVersion[0] = HIWORD(pFileInfo->dwProductVersionMS); 
		m_nProdVersion[1] = LOWORD(pFileInfo->dwProductVersionMS);
		m_nProdVersion[2] = HIWORD(pFileInfo->dwProductVersionLS);
		m_nProdVersion[3] = LOWORD(pFileInfo->dwProductVersionLS); 

		CString strVersion ;
		//strVersion.Format(_T("The file's version : %d.%d.%d.%d"),m_nProdVersion[0],m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]);
		strVersion.Format(_T("%d.%d.%d.%d"),m_nProdVersion[0],m_nProdVersion[1],m_nProdVersion[2],m_nProdVersion[3]);

		GlobalUnlock(hMem);
		GlobalFree(hMem);

		return strVersion;
		//AfxMessageBox(strVersion);
	}

}
]]>
http://www.youthtribe.com/archives/1739/feed 0