Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get version info? 2

Status
Not open for further replies.

Totte

Programmer
Jun 6, 2001
317
0
0
SE
WinXP, BCB6.

Have a project that the customer repeatly wants new ways of doing things. Mainly it's expansion of an existing project but i would like to be compatible so i don't need to copy and rename a lot.

I back-up with the correct names so now i have one problem:
I would like to read the Major & Minor version info that i'm writing into the project, maybe even the "Build" value too... but how?

Get_VersionMajor... don't work, i have tried the example shown in the Help under "FileVersion" but it don't work either.

I find it hard to believe that such a simple task should be so complicated and I'm sure i have missed something obvious... but what?

Totte
Keep making it perfect and it will end up broken.
 
Using Builder 6 (probably same with other versions) on Windows XP:

Code:
void VersionInfo::GetVersion(int& Major,
                             int& Minor,
                             int& Release,
                             int& Build)
{
   DWORD tempHandle = 0;
   DWORD infoLen;

   VS_FIXEDFILEINFO* fileInfo;

   //-------------------------------------------------------------------------//
   //                                                                         //
   // Obtain the length of the version information available.                 //
   // If the length is not zero, create a buffer of the appropriate size, and //
   // retrieve the information block.                                         //
   // Then retrieve the language-independant version information.             //
   //                                                                         //
   //-------------------------------------------------------------------------//

   infoLen = GetFileVersionInfoSize(ParamStr(0).c_str(), &tempHandle);

   if (infoLen > 0)
   {
      char* pBuf = (char *) malloc(infoLen);

      unsigned int valueLen;

      GetFileVersionInfo(ParamStr(0).c_str(), 0, infoLen, pBuf);

      if (VerQueryValue(pBuf, "\\", (void **)&fileInfo, &valueLen))
      {
         Major   = (int)((fileInfo->dwFileVersionMS >> 16) & 0xffff);
         Minor   = (int)((fileInfo->dwFileVersionMS      ) & 0xffff);
         Release = (int)((fileInfo->dwFileVersionLS >> 16) & 0xffff);
         Build   = (int)((fileInfo->dwFileVersionLS      ) & 0xffff);
      }
      else
      {
         Major   = 0;
         Minor   = 0;
         Release = 0;
         Build   = 0;
      }

      //----------------------------------------------------------------------//
      //                                                                      //
      // Free buffer.                                                         //
      //                                                                      //
      //----------------------------------------------------------------------//

      free(pBuf);
   }
   else
   {
      //----------------------------------------------------------------------//
      //                                                                      //
      // Unable to obtain file version information.                           //
...
 
Thank You, works like a charm!

I'm just a little baffled that the versions and such are not existing like som sort of #define but never mind, this solution works and I'm fine with that.

Totte
Keep making it perfect and it will end up broken.
 
Good job! I just so happened to need the same thing today and had to do about 3 seconds of looking. Thanks!

Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top