Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Get version information of the application at runtime


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Apr 4, 2016 10:01 PM Last Post By: Florian Wolf
Florian Wolf

Posts: 20
Registered: 4/8/16
Get version information of the application at runtime  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2016 4:22 AM
I try to get the versoin information of my application (which can be set in the project options) at runtime.

I found the code:

TCHAR szVersionFile[MAX_PATH];
	GetModuleFileName(NULL, szVersionFile, MAX_PATH );
 
	DWORD  verHandle = NULL;
	UINT   size      = 0;
	LPBYTE lpBuffer  = NULL;
	DWORD  verSize   = GetFileVersionInfoSize( szVersionFile, &verHandle);
 
	if (verSize != NULL)
	{
		LPSTR verData = new char[verSize];
 
		if (GetFileVersionInfo( szVersionFile, verHandle, verSize, verData))
		{
			if (VerQueryValue(verData,TEXT("\\"),(VOID FAR* FAR*)&lpBuffer,&size))
			{
				if (size)
				{
					VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
					if (verInfo->dwSignature == 0xfeef04bd)
					{
 
						int iHauptversion = verInfo->dwFileType;
						int iNebenversion = verInfo->dwFileSubtype;
 
						LabelVersion->Caption = "V. " + IntToStr(iHauptversion) + "." + IntToStr(iNebenversion);
					}
				}
			}
		}
		delete[] verData;
	}


But I always get V. 1.0.
Is there a simple way to get the version information?
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Get version information of the application at runtime
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2016 11:21 AM   in response to: Florian Wolf in response to: Florian Wolf
El 04/04/2016 a las 13:22, Florian Wolf escribió:
I try to get the versoin information of my application (which can be set in the project options) at runtime.

I found the code:

TCHAR szVersionFile[MAX_PATH];
	GetModuleFileName(NULL, szVersionFile, MAX_PATH );
 
	DWORD  verHandle = NULL;
	UINT   size      = 0;
	LPBYTE lpBuffer  = NULL;
	DWORD  verSize   = GetFileVersionInfoSize( szVersionFile, &verHandle);
 
	if (verSize != NULL)
	{
		LPSTR verData = new char[verSize];
 
		if (GetFileVersionInfo( szVersionFile, verHandle, verSize, verData))
		{
			if (VerQueryValue(verData,TEXT("\\"),(VOID FAR* FAR*)&lpBuffer,&size))
			{
				if (size)
				{
					VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
					if (verInfo->dwSignature == 0xfeef04bd)
					{
 
						int iHauptversion = verInfo->dwFileType;
						int iNebenversion = verInfo->dwFileSubtype;

Your are using incorrect structure fields.
Try this:

	int iHauptversion = HIWORD(verInfo->dwFileVersionMS);
	int iNebenversion = LOWORD(verInfo->dwFileVersionMS);


Edited by: Antonio Estevez on Apr 4, 2016 11:31 AM
Florian Wolf

Posts: 20
Registered: 4/8/16
Re: Get version information of the application at runtime  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 4, 2016 10:01 PM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 04/04/2016 a las 13:22, Florian Wolf escribió:

Your are using incorrect structure fields.
Try this:

	int iHauptversion = HIWORD(verInfo->dwFileVersionMS);
	int iNebenversion = LOWORD(verInfo->dwFileVersionMS);


Edited by: Antonio Estevez on Apr 4, 2016 11:31 AM

Thank you very much. That helped me a lot.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02