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);
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.