by Marco Turco » Tue May 06, 2008 1:07 pm
Here it is.
// Just for FWH 32 bits
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function GetExeVersion(cFile)
return( ctod( GetFileVersionInfo( cFile, 13 ) ) )
return nil
//----------------------------------------------------------------------------//
#pragma BEGINDUMP
#include <windows.h>
#include <hbapi.h>
HB_FUNC( GETFILEVERSIONINFO )
{
char * szFile = hb_parc( 1 );
UINT uAction = ISNUM( 2 ) ? hb_parni( 2 ) : 1;
DWORD dwHandle = 0;
DWORD dwSize = GetFileVersionInfoSize( szFile, &dwHandle );
char * szOut = NULL;
BOOL bOk = FALSE;
if( dwSize )
{
char * szBlock = ( char * ) hb_xgrab( 255 );
char * szSubBlock = ( char * ) hb_xgrab( 255 );
HGLOBAL hMem = GlobalAlloc( GMEM_MOVEABLE, dwSize );
VS_FIXEDFILEINFO * vsInfo;
UINT nLen = 0;
if( hMem )
{
LPVOID pMem = GlobalLock( hMem );
if( pMem && GetFileVersionInfo( szFile, dwHandle, dwSize, pMem ) )
{
if( VerQueryValue( pMem, "\\VarFileInfo\\Translation", ( LPVOID * ) &vsInfo, &nLen ) )
{
*( LPDWORD ) vsInfo = MAKELONG( HIWORD( *( LPDWORD ) vsInfo ), LOWORD( *( LPDWORD ) vsInfo ) );
sprintf( szBlock, "\\StringFileInfo\\%08lx\\", *( LPDWORD )( vsInfo ) );
switch( uAction )
{
case 1:
sprintf( szSubBlock, "%s%s", szBlock, "Comments" );
break;
case 2:
sprintf( szSubBlock, "%s%s", szBlock, "CompanyName" );
break;
case 3:
sprintf( szSubBlock, "%s%s", szBlock, "FileDescription" );
break;
case 4:
sprintf( szSubBlock, "%s%s", szBlock, "FileVersion" );
break;
case 5:
sprintf( szSubBlock, "%s%s", szBlock, "InternalName" );
break;
case 6:
sprintf( szSubBlock, "%s%s", szBlock, "LegalCopyright" );
break;
case 7:
sprintf( szSubBlock, "%s%s", szBlock, "LegalTrademarks" );
break;
case 8:
sprintf( szSubBlock, "%s%s", szBlock, "OriginalFilename" );
break;
case 9:
sprintf( szSubBlock, "%s%s", szBlock, "PrivateBuild" );
break;
case 10:
sprintf( szSubBlock, "%s%s", szBlock, "ProductName" );
break;
case 11:
sprintf( szSubBlock, "%s%s", szBlock, "ProductVersion" );
break;
case 12:
sprintf( szSubBlock, "%s%s", szBlock, "SpecialBuild" );
break;
case 13:
sprintf( szSubBlock, "%s%s", szBlock, "DateOfRelease" );
break;
}
if( VerQueryValue( pMem, szSubBlock, ( LPVOID * ) &szOut, &nLen ) )
bOk = TRUE;
hb_xfree( szBlock );
hb_xfree( szSubBlock );
}
GlobalUnlock( hMem );
GlobalFree( hMem );
}
}
}
if( bOk )
hb_retc( szOut );
else
hb_retc( "" );
}
#pragma ENDDUMP
//----------------------------------------------------------------------------//
Best Regards,
Marco Turco
SOFTWARE XP LLP