File Version Info

Posted on 2003-03-31
Medium Priority
Last Modified: 2008-03-03
Can you send me a code that extracts version info of specific file. It should be language independent.

Question by:YisraelE
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

mnashadka earned 280 total points
ID: 8241528
I don't believe there is such a thing as "language independent".  If you want a C++ Windows version, here's something I hacked up (with some help from the MSDN website):
std::string GetVersion(char *file_name)
  std::string version_string;
     DWORD version_size = 0, dummy_size = 0;
  LPVOID version_ptr;
  DWORD lang;
  unsigned int v_size = 0;
  // Get the size
  version_size = GetFileVersionInfoSize(file_name, &dummy_size);
  if(version_size != 0)
    char file_version[256] = {0};
    char *version_info = new char[version_size];

    // Get the info
    if(GetFileVersionInfo(file_name, 0, version_size, version_info))
      int retVal = VerQueryValue(version_info, file_version, &version_ptr, &v_size);

      // Find the language description
      if (retVal && version_size==4)
        memcpy(&lang, version_ptr, 4);
        sprintf(file_version, "\\StringFileInfo\\%02X%02X%02X%02X\\FileVersion",
          (lang & 0xff00)>>8, lang & 0xff, (lang & 0xff000000)>>24,
          (lang & 0xff0000)>>16);            
        sprintf(file_version, "\\StringFileInfo\\%04X04B0\\FileVersion",

      // Get the version
      VerQueryValue(version_info, file_version, &version_ptr, &v_size);
      // Reset it
      version_string = reinterpret_cast<char *>(version_ptr);
    delete [] version_info;

  return version_string;


Expert Comment

ID: 8247107
Which only works, if a version info resource was compiled into the executable, which isn't by all means necessary. Basically, there is no such thing as a file version that would work across platforms. If you need version info, make sure to somehow compile into the executable and provide means for extracting them.


Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question