How to get version information of an application

30 03 2009


Sometimes we really want to know the version of our application. It’s not a matter of concern, just right click on the application and look it at on the second tab of the Properties dialog. Ok that is fine. But how could we check it in our C++ application.


Window API’s have different methods to accomplish this. GetFileVersionInfo function retrieves the version information of a file. Call GetFileVersionInfoSize function to get the size of the version information buffer. VerQueryValue function gets the information into a corresponding structure.


void GetFileVersionOfApplication()
   //give your application full path
   LPTSTR lpszFilePath = "D:\\SAN\\MyTest.exe";

   DWORD dwDummy;
   DWORD dwFVISize = GetFileVersionInfoSize( lpszFilePath , &dwDummy );

   LPBYTE lpVersionInfo = new BYTE[dwFVISize];

   GetFileVersionInfo( lpszFilePath , 0 , dwFVISize , lpVersionInfo );

   UINT uLen;

   VerQueryValue( lpVersionInfo , _T("\\") , (LPVOID *)&lpFfi , &uLen );

   DWORD dwFileVersionMS = lpFfi->dwFileVersionMS;
   DWORD dwFileVersionLS = lpFfi->dwFileVersionLS;

   delete [] lpVersionInfo;

   printf( "Higher: %x\n" , dwFileVersionMS );

   printf( "Lower: %x\n" , dwFileVersionLS );

   DWORD dwLeftMost     = HIWORD(dwFileVersionMS);
   DWORD dwSecondLeft   = LOWORD(dwFileVersionMS);
   DWORD dwSecondRight  = HIWORD(dwFileVersionLS);
   DWORD dwRightMost    = LOWORD(dwFileVersionLS);

   CString str;

   str.Format("Version: %d.%d.%d.%d\n" , dwLeftMost, dwSecondLeft,
      dwSecondRight, dwRightMost);



Don’t forget to include Version.lib to your application.




6 responses

13 02 2012
Vijay Patel

I have cam up up with following code for version but along with version info I also need Build Date in VC++ could you please help with following code

I am new to VC++ or never work with .
Thank you very much.

13 02 2012
Sanoop S P

Hello Vijay,

Thanks for you comment.

You can use the GetFileTime( ) API to retrieve the Created/LastAccessed/and Last Modified times of a file.
Please see below like for a sample code.

Please revert back to me if you need any more help.

With Best Regards,

13 02 2012
Vijay Patel

I have received error C2146: syntex error : missing ‘;’ before indentifier ‘LPTSTR’

13 02 2012
Sanoop S P

Make it as CString data-type instead of LPTSTR

8 04 2012

is any way to get the string table information also?

10 04 2012
Sanoop S P

Hello Sarath,

Could you please try with LoadString method.
CString str;

Thanks and Regards

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: