vc++에서 얻은 dll 버전 정보

1244 단어 VC/MFC
먼저 #pragma comment(lib, Version.lib)를 추가합니다.
CString GetProductVersion(LPCTSTR lpszFileName)   
{   
	CString strVersion;   
	TCHAR szSrcfn[MAX_PATH]; //            
	if(lpszFileName == NULL)   
		::GetModuleFileName(NULL, szSrcfn, sizeof(szSrcfn));   
	else   
		lstrcpy(szSrcfn, lpszFileName);   

	//         
	DWORD dwVerHnd = 0;   
	DWORD dwVerInfoSize = ::GetFileVersionInfoSize(szSrcfn, &dwVerHnd);   
	if(dwVerInfoSize)   
	{   
		HANDLE hMem;   
		LPVOID lpvMem;   
		unsigned int uInfoSize = 0;   
		VS_FIXEDFILEINFO * pFileInfo;   

		hMem = ::GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);   
		lpvMem = ::GlobalLock(hMem);   
		::GetFileVersionInfo(szSrcfn, dwVerHnd, dwVerInfoSize, lpvMem);   
		::VerQueryValue(lpvMem, (LPTSTR)_T("\\"), (void**)&pFileInfo, &uInfoSize);   

		WORD nVer[4];   
		nVer[0] = HIWORD(pFileInfo->dwProductVersionMS);   
		nVer[1] = LOWORD(pFileInfo->dwProductVersionMS);   
		nVer[2] = HIWORD(pFileInfo->dwProductVersionLS);   
		nVer[3] = LOWORD(pFileInfo->dwProductVersionLS);   
		strVersion.Format(_T("%d.%d.%d.%d"), nVer[0], nVer[1],nVer[2],nVer[3]);   

		::GlobalUnlock(hMem);   
		::GlobalFree(hMem);   
	}   

	return strVersion;   
}

좋은 웹페이지 즐겨찾기