Click here to Skip to main content
Click here to Skip to main content
Go to top

How to retrieve file information

, 27 Jun 2005
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

shaman74
Web Developer
Italy Italy
No Biography provided

Comments and Discussions

 
QuestionWhat are the admission parameters of the function? PinmemberMerinat16-Jul-07 3:16 
GeneralCouple of issues PinmemberFlySolo12-Dec-06 13:25 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 28 Jun 2005
Article Copyright 2005 by shaman74
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid