Click here to Skip to main content
Licence 
First Posted 27 Jun 2005
Views 26,712
Bookmarked 12 times

How to retrieve file information

By | 27 Jun 2005 | Article
A simple function to retrieve file information as file version, product info etc.

Introduction

This article reports a short function (Borland C++) useful to retrieve all the information stored in a file. Information like product info, file version, and so on can be retrieved.

The body of the function is:

int GetFileInfo(AnsiString filepath, 
    AnsiString fileinfo, AnsiString *fileinfovalue)
{
  DWORD whandle;
  DWORD rsize;
  int retval;

  rsize=GetFileVersionInfoSize(filepath.c_str(), &whandle);
  if (rsize>0)
  {
    unsigned char *buffer = new unsigned char[rsize];
    if (GetFileVersionInfo(Application->ExeName.c_str(), 
                                   whandle, rsize, buffer))
    {
      unsigned short *subBlock;
      unsigned int len = 0;
      if (VerQueryValue(buffer, 
          "\\VarFileInfo\\Translation", (void **)&subBlock, &len))
      {
        AnsiString spv;
        char *versionInfo;
        len=0;

        spv.sprintf("\\StringFileInfo\\%04x%04x\\", 
                         subBlock[0], subBlock[1]);
        spv+=fileinfo;
        if (VerQueryValue(buffer, spv.c_str(), (void *
                                *)&versionInfo, &len))
        {
          *fileinfovalue=versionInfo;
          retval=0;
        }
        else
          retval=1;
      }
      else
        retval=2;
    }
    else
      retval=3;
  }
  else
    retval=4;

  return retval;
}

And it's used as:

AnsiString asv;
GetFileInfo(Application->ExeName, "ProductVersion", &asv);
ShowMessage(asv);

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

shaman74

Web Developer

Italy Italy

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWhat are the admission parameters of the function? PinmemberMerinat3:16 16 Jul '07  
GeneralCouple of issues PinmemberFlySolo13:25 12 Dec '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 28 Jun 2005
Article Copyright 2005 by shaman74
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid