Util.cpp
/*--- function MakeVersionStringForFile -------------------------------
 *
 *  Return an ASCII version of the Windows VERSION resource in 
 *  a given file.
 *
 *  Entry:  filename          is the name of a file with a version
 *                            resource (usually a .EXE or .DLL).
 *          pszVersionString  points to a buffer that's big enough
 *                            to hold the version number; 17 bytes
 *                            should always be enough.
 *  Exit:   pszVersionString  points to a zero-terminated version
 *                            string of the form w.x.y.z
 *                            If the resource could not be found, a
 *                            zero-length string is returned.
 */
function MakeVersionStringForFile
Return an ASCII version of the Windows VERSION resource in
a given file.

filename          is the name of a file with a version
resource (usually a .EXE or .DLL).
pszVersionString  points to a buffer that's big enough
to hold the version number; 17 bytes
should always be enough.
Exit:   pszVersionString  points to a zero-terminated version
string of the form w.x.y.z
If the resource could not be found, a
zero-length string is returned.
function MakeVersionStringForFile Return an ASCII version of the Windows VERSION resource in a given file . filename is the name of a file with a version resource ( usually a . EXE or . DLL ) . pszVersionString points to a buffer that ' s big enough to hold the version number ; 17 bytes should always be enough . Exit : pszVersionString points to a zero - terminated version string of the form w . x . y . z If the resource could not be found a zero - length string is returned .
void MakeVersionStringForFile(char *filename, char *pszVersionString)
{
   char * pszSubBlock = TEXT("\\"); 
   void *verbuf;
   DWORD dwhandle;
   DWORD dwvers_size;
   unsigned int uValLen;
   pszVersionString[0] = '\0';
   dwvers_size = GetFileVersionInfoSize(filename,&dwhandle);
   if(dwvers_size) {
      verbuf = malloc(dwvers_size);
      GetFileVersionInfo(filename,dwhandle,dwvers_size,verbuf);
      VS_FIXEDFILEINFO *pinfo;
      if(VerQueryValue(verbuf,pszSubBlock,(void **)&pinfo,&uValLen)) {
         wsprintf(pszVersionString,"%d.%d.%d.%d",
            0xffff & (pinfo->dwFileVersionMS>>16),
            0xffff & pinfo->dwFileVersionMS,
            0xffff & (pinfo->dwFileVersionLS>>16),
            0xffff & pinfo->dwFileVersionLS);
      }
      if(verbuf) free(verbuf);
   }
}
void MakeVersionStringForFile ( char * filename , char * pszVersionString ) { char * pszSubBlock = TEXT ( " \\ " ) ; void * verbuf ; DWORD dwhandle ; DWORD dwvers_size ; unsigned int uValLen ; pszVersionString [ 0 ] = ' \0 ' ; dwvers_size = GetFileVersionInfoSize ( filename , & dwhandle ) ; if ( dwvers_size ) { verbuf = malloc ( dwvers_size ) ; GetFileVersionInfo ( filename , dwhandle , dwvers_size , verbuf ) ; VS_FIXEDFILEINFO * pinfo ; if ( VerQueryValue ( verbuf , pszSubBlock , ( void * * ) & pinfo , & uValLen ) ) { wsprintf ( pszVersionString , " " , 0xffff & ( pinfo -> dwFileVersionMS >> 16 ) , 0xffff & pinfo -> dwFileVersionMS , 0xffff & ( pinfo -> dwFileVersionLS >> 16 ) , 0xffff & pinfo -> dwFileVersionLS ) ; } if ( verbuf ) free ( verbuf ) ; } }
function MakeVersionStringForFile
  Return an ASCII version of the Windows VERSION resource in
  a given file.
function MakeVersionStringForFile Return an ASCII version of the Windows VERSION resource in a given file .