Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I work on a few MFC apps where I want them to display their own FILEVERSION information in the titlebar. I've seen articles on how to get the FILEVERSION information from the resources of other apps & DLLs, but in my case, I want the application to display its own FILEVERSION information. How can this be done within the MFC app?
Posted

Assuming you have the full file spec of your image.

CString FileHelper::GetFileVersionString(CString FileName)
{
	DWORD dwHandle, dwLen;
	CString v = "0.0.0";
	if ((dwLen = GetFileVersionInfoSize((LPCTSTR)FileName, &dwHandle)) != 0)
	{
		LPTSTR lpData = (LPTSTR)malloc(dwLen);
		if (GetFileVersionInfo((LPCTSTR)FileName, dwHandle, dwLen, lpData) != 0)
		{
			UINT BufLen;
			VS_FIXEDFILEINFO *pFileInfo;
			if (VerQueryValue(lpData, "\\", (LPVOID *)&pFileInfo, (PUINT)&BufLen) != 0)
			{
				if (LOWORD(pFileInfo->dwFileVersionLS) == 0)
					v.Format("%d.%d.%d", HIWORD(pFileInfo->dwFileVersionMS), LOWORD(pFileInfo->dwFileVersionMS), HIWORD(pFileInfo->dwFileVersionLS));
				else
					v.Format("%d.%d.%d.%d", HIWORD(pFileInfo->dwFileVersionMS), LOWORD(pFileInfo->dwFileVersionMS), HIWORD(pFileInfo->dwFileVersionLS), LOWORD(pFileInfo->dwFileVersionLS));
			}
		}
		free(lpData);
	}
	return v;
}
 
Share this answer
 
Comments
CalicoSkies 1-Nov-11 19:44pm    
1. I'm not sure what you mean by "image".
2. I want to get the version of the application from its own resources.. What filename would I pass to this function?
Chuck O'Toole 1-Nov-11 19:56pm    
ah, "image" as in binary that is running. Pass it the file name of your application.
 
Share this answer
 
Comments
CalicoSkies 1-Nov-11 19:53pm    
Thanks. I downloaded the code from that page, but it has compile & link issues.. I got it to compile by adding a type declaration to a loop variable, but now it has a linker error - It gives an "unresolved external symbol" error for CFileVersionInfo::vftable. How were you able to get this to compile & link?
Chuck O'Toole 1-Nov-11 20:08pm    
The date on that article is 19 Jun 2002. It's likely that the project was built against an older compiler than you have and there have been some changes that require source and/or symbol changes over the years. The bottom line on articles is "they worked when they were posted but probably not kept up to date"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900