src/SeeDll/Packet32.c
/*! 
  \brief Returns the version of a dll or exe file 
  \param FileName Name of the file whose version has to be retrieved.
  \param VersionBuff Buffer that will contain the string with the file version.
  \param VersionBuffLen Length of the buffer pointed by VersionBuff.
  \return If the function succeeds, the return value is TRUE.

  \note uses the GetFileVersionInfoSize() and GetFileVersionInfo() WIN32 API functions
*/
\brief Returns the version of a dll or exe file
\param FileName Name of the file whose version has to be retrieved.
\param VersionBuff Buffer that will contain the string with the file version.
\param VersionBuffLen Length of the buffer pointed by VersionBuff.
\return If the function succeeds, the return value is TRUE.

\note uses the GetFileVersionInfoSize() and GetFileVersionInfo() WIN32 API functions
\ brief Returns the version of a dll or exe file \ param FileName Name of the file whose version has to be retrieved . \ param VersionBuff Buffer that will contain the string with the file version . \ param VersionBuffLen Length of the buffer pointed by VersionBuff . \ return If the function succeeds the return value is TRUE . \ note uses the GetFileVersionInfoSize () and GetFileVersionInfo () WIN32 API functions
BOOL PacketGetFileVersion(LPTSTR FileName, PCHAR VersionBuff, UINT VersionBuffLen)
{
    DWORD   dwVerInfoSize;  
    DWORD   dwVerHnd=0;   
	LPSTR   lpstrVffInfo;
	UINT	cbTranslate, dwBytes;
	TCHAR	SubBlock[64];
	PVOID	lpBuffer;
	PCHAR	TmpStr;
	struct LANGANDCODEPAGE {
	  WORD wLanguage;
	  WORD wCodePage;
	} *lpTranslate;
	ODS("PacketGetFileVersion\n");
    dwVerInfoSize = GetFileVersionInfoSize(FileName, &dwVerHnd);
    if (dwVerInfoSize) 
	{
        lpstrVffInfo = GlobalAllocPtr(GMEM_MOVEABLE, dwVerInfoSize);
		if (lpstrVffInfo == NULL)
		{
			ODS("PacketGetFileVersion: failed to allocate memory\n");
			return FALSE;
		}
		if(!GetFileVersionInfo(FileName, dwVerHnd, dwVerInfoSize, lpstrVffInfo)) 
		{
			ODS("PacketGetFileVersion: failed to call GetFileVersionInfo\n");
            GlobalFreePtr(lpstrVffInfo);
			return FALSE;
		}
		if(!VerQueryValue(lpstrVffInfo,	TEXT("\\VarFileInfo\\Translation"),	(LPVOID*)&lpTranslate, &cbTranslate))
		{
			ODS("PacketGetFileVersion: failed to call VerQueryValue\n");
            GlobalFreePtr(lpstrVffInfo);
			return FALSE;
		}
		wsprintf( SubBlock, 
			TEXT("\\StringFileInfo\\%04x%04x\\FileVersion"),
			(*lpTranslate).wLanguage,
			(*lpTranslate).wCodePage);
		if(!VerQueryValue(lpstrVffInfo, SubBlock, &lpBuffer, &dwBytes))
		{
			ODS("PacketGetFileVersion: failed to call VerQueryValue\n");
            GlobalFreePtr(lpstrVffInfo);
			return FALSE;
		}
		TmpStr = WChar2SChar(lpBuffer);
		if(strlen(TmpStr) >= VersionBuffLen)
		{
			ODS("PacketGetFileVersion: Input buffer too small\n");
            GlobalFreePtr(lpstrVffInfo);
            GlobalFreePtr(TmpStr);
			return FALSE;
		}
		strcpy(VersionBuff, TmpStr);
        GlobalFreePtr(lpstrVffInfo);
        GlobalFreePtr(TmpStr);
	  } 
	else 
	{
		ODSEx("PacketGetFileVersion: failed to call GetFileVersionInfoSize, LastError = %d\n", GetLastError());
		return FALSE;
	} 
	return TRUE;
}
BOOL PacketGetFileVersion ( LPTSTR FileName , PCHAR VersionBuff , UINT VersionBuffLen ) { DWORD dwVerInfoSize ; DWORD dwVerHnd = 0 ; LPSTR lpstrVffInfo ; UINT cbTranslate , dwBytes ; TCHAR SubBlock [ 64 ] ; PVOID lpBuffer ; PCHAR TmpStr ; struct LANGANDCODEPAGE { WORD wLanguage ; WORD wCodePage ; } * lpTranslate ; ODS ( " \n " ) ; dwVerInfoSize = GetFileVersionInfoSize ( FileName , & dwVerHnd ) ; if ( dwVerInfoSize ) { lpstrVffInfo = GlobalAllocPtr ( GMEM_MOVEABLE , dwVerInfoSize ) ; if ( lpstrVffInfo == NULL ) { ODS ( " \n " ) ; return FALSE ; } if ( ! GetFileVersionInfo ( FileName , dwVerHnd , dwVerInfoSize , lpstrVffInfo ) ) { ODS ( " \n " ) ; GlobalFreePtr ( lpstrVffInfo ) ; return FALSE ; } if ( ! VerQueryValue ( lpstrVffInfo , TEXT ( " \\ \\ " ) , ( LPVOID * ) & lpTranslate , & cbTranslate ) ) { ODS ( " \n " ) ; GlobalFreePtr ( lpstrVffInfo ) ; return FALSE ; } wsprintf ( SubBlock , TEXT ( " \\ \\ \\ " ) , ( * lpTranslate ) . wLanguage , ( * lpTranslate ) . wCodePage ) ; if ( ! VerQueryValue ( lpstrVffInfo , SubBlock , & lpBuffer , & dwBytes ) ) { ODS ( " \n " ) ; GlobalFreePtr ( lpstrVffInfo ) ; return FALSE ; } TmpStr = WChar2SChar ( lpBuffer ) ; if ( strlen ( TmpStr ) >= VersionBuffLen ) { ODS ( " \n " ) ; GlobalFreePtr ( lpstrVffInfo ) ; GlobalFreePtr ( TmpStr ) ; return FALSE ; } strcpy ( VersionBuff , TmpStr ) ; GlobalFreePtr ( lpstrVffInfo ) ; GlobalFreePtr ( TmpStr ) ; } else { ODSEx ( " \n " , GetLastError ( ) ) ; return FALSE ; } return TRUE ; }
\brief Returns the version of a dll or exe file
\param FileName Name of the file whose version has to be retrieved.
\ brief Returns the version of a dll or exe file \ param FileName Name of the file whose version has to be retrieved .
// Size of version information block
 // An 'ignored' parameter, always '0'
 // Structure used to store enumerated languages and code pages.
 // Now lets dive in and pull out the version information:
 // Read the list of languages and code pages.
 // Create the file version string for the first (i.e. the only one) language.
 // Retrieve the file version string for the language.
 // Convert to ASCII
