Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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

580 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