How do I extract the version of an EXE or DLL?

I make no promises as to quality, but it _does_ work. All error handling and parameter validation has been removed for brevity.

GetVersionOfFile (char * pszAppName, // file
                  char * pszVerBuff, // receives version
                  int    iVerBuffLen, // size of buffer
                  char * pszLangBuff, // receives language
                  int   iLangBuffLen) // size of buffer
{
   DWORD   dwScratch;
   DWORD * pdwLangChar;
   DWORD   dwInfSize ;
   UINT    uSize;

   BYTE *  pbyInfBuff;
   char    szVersion [32];
   char    szResource [80];
   char *  pszVersion = szVersion;

   dwInfSize = GetFileVersionInfoSize (pszAppName, &dwScratch);

   if (dwInfSize)
   {
      pbyInfBuff = new BYTE [dwInfSize];
      if (pbyInfBuff)
      {
         ZeroMemory (pbyInfBuff, dwInfSize);
         if (GetFileVersionInfo (pszAppName, 0, dwInfSize, pbyInfBuff))
         {
            if (VerQueryValue (pbyInfBuff,
                               "file://VarFileInfo//Translation",
                               (void**)(&pdwLangChar),
                               &uSize))
            {
               if (VerLanguageName (LOWORD (*pdwLangChar),
                                    szResource,
                                    sizeof (szResource)))
               {
                  strncpy (pszLangBuff, szResource, iLangBuffLen);
               }
               wsprintf (szResource, "file://StringFileInfo//%04X%04X//FileVersion",
                         LOWORD (*pdwLangChar), 
                         HIWORD (*pdwLangChar));
               if (VerQueryValue (pbyInfBuff,
                                  szResource,
                                  (void**)(&pszVersion),
                                  &uSize))
               {
                  strncpy (pszVerBuff, pszVersion, iVerBuffLen-1);
               }
            }
         }
         delete [] pbyInfBuff;
      }
   }
}
Download