FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Versi贸n del ejecutable
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM

Versi贸n del ejecutable

Posted: Sat Apr 25, 2015 04:15 PM

驴Como puedo obtener el n煤mero de versi贸n del ejecutable que se le asigna en el RC y se muestra en las propiedades del archivo con click derecho del mouse?

Saludos

Quique
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM

Re: Versi贸n del ejecutable

Posted: Sat Apr 25, 2015 05:13 PM

Hola,
En tu archivo de recursos, opci贸n "New" hay una opci贸n para crear la instancia "Versi贸n", all铆 le asignas los datos que necesites....
Salu2

Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM

Re: Versi贸n del ejecutable

Posted: Mon Apr 27, 2015 04:50 AM

Gracias Willi por responder, pero lo que necesito es obtener esa informaci贸n desde el ejecutable, o sea, en el editor de recursos le pongo versi贸n 1.0.0.2 驴como obtengo ese dato dentro del ejecutable?

Saludos

Quique
Posts: 1380
Joined: Fri Oct 14, 2005 01:28 PM

Re: Versi贸n del ejecutable

Posted: Mon Apr 27, 2015 11:55 AM
Quique;
Esto comparti贸, si mal no recuerdo Antonio.
Code (fw): Select all Collapse
// Just for FWH 32 bits
// Author: Anonimo

#include "FiveWin.ch"

//----------------------------------------------------------------------------//
/*
function Main()

聽 聽local n

聽 聽for n = 1 to 12
聽 聽 聽 聽MsgInfo( GetFileVersionInfo( "filever.exe", n ) )
聽 聽next

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, "Author" );
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽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, "AppBuild" );
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽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

//----------------------------------------------------------------------------//
Resistencia - "Ciudad de las Esculturas"

Chaco - Argentina
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM

Re: Versi贸n del ejecutable

Posted: Mon Apr 27, 2015 02:26 PM
Gracias Mario, pero no funciona, de hecho ya la hab铆a visto pero volv铆 a probar con lo que pusiste por si hab铆a cambios, de hecho tuve que modificar ISNUM por HB_ISNUM y me marc贸 dos warnings pero eso no lo toque.

En mi RC tengo

Code (fw): Select all Collapse
1 VERSIONINFO
FILEVERSION 2, 4, 0, 1
PRODUCTVERSION 4, 2, 0, 0
FILEOS VOS__WINDOWS16
FILETYPE VFT_DLL
{
聽BLOCK "StringFileInfo"


y al dar las propiedades del archivo me dice
Versi贸n del archivo 2.4.0.1

Pero este n煤mero no aparece en ning煤n mensaje, ni siqueira separado como para decir hay que juntarlos, y de hecho, intent茅 cambiando el for de 0 a 20 por si acaso, pero nada.
Saludos

Quique
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Versi贸n del ejecutable

Posted: Mon Apr 27, 2015 08:33 PM
Quique,

Revisa este c贸digo que encontr茅 aqui:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms647003%28v=vs.85%29.aspx

Code (fw): Select all Collapse
BOOL GetAppVersion( char *LibName, WORD *MajorVersion, WORD *MinorVersion, WORD *BuildNumber, WORD *RevisionNumber )
{
 DWORD dwHandle, dwLen;
 UINT BufLen;
 LPTSTR lpData;
 VS_FIXEDFILEINFO *pFileInfo;
 dwLen = GetFileVersionInfoSize( LibName, &dwHandle );
 if (!dwLen) 
  return FALSE;

 lpData = (LPTSTR) malloc (dwLen);
 if (!lpData) 
  return FALSE;

 if( !GetFileVersionInfo( LibName, dwHandle, dwLen, lpData ) )
 {
  free (lpData);
  return FALSE;
 }
 if( VerQueryValue( lpData, "\\", (LPVOID *) &pFileInfo, (PUINT)&BufLen ) ) 
 {
  *MajorVersion = HIWORD(pFileInfo->dwFileVersionMS);
  *MinorVersion = LOWORD(pFileInfo->dwFileVersionMS);
  *BuildNumber = HIWORD(pFileInfo->dwFileVersionLS);
  *RevisionNumber = LOWORD(pFileInfo->dwFileVersionLS);
  free (lpData);
  return TRUE;
 }
 free (lpData);
 return FALSE;
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM

Re: Versi贸n del ejecutable

Posted: Mon Apr 27, 2015 11:38 PM
Encontr茅 esto. Talvez si alguien se decide "traducir" y lo prueba.
Code (fw): Select all Collapse
'------------------------------------------------------------------------------
' Averiguar la versi贸n de un fichero (ejecutable o DLL)             (24/Jun/08)
'
' 漏Guillermo 'guille' Som, 2008
'------------------------------------------------------------------------------
Option Strict On

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports System.Diagnostics

Public Class Form1

    Private Sub btnMostrar_Click(ByVal sender As Object, _
                                 ByVal e As EventArgs) _
                                 Handles btnMostrar.Click
        txtInfo.Text = FileVersion(txtFichero.Text)
    End Sub

    Private Sub btnExaminar_Click(ByVal sender As Object, _
                                  ByVal e As EventArgs) _
                                  Handles btnExaminar.Click
        Dim ofD As New OpenFileDialog

        With ofD
            .FileName = txtFichero.Text
            .Filter = "Ejecutables (*.exe; *.dll)|*.exe;*.dll"
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                txtFichero.Text = .FileName
            End If
        End With
    End Sub

    Private Function FileVersion(ByVal elPath As String) As String
        Dim fvi As System.Diagnostics.FileVersionInfo = _
                System.Diagnostics.FileVersionInfo.GetVersionInfo(elPath)
        'Return fvi.FileVersion
        'Return fvi.ProductVersion

        Dim sb As New System.Text.StringBuilder
        sb.AppendLine("ProductName:     " & fvi.ProductName)
        sb.AppendLine("FileDescription: " & fvi.FileDescription)
        sb.AppendLine("FileVersion:     " & fvi.FileVersion)
        sb.AppendLine("ProductVersion:  " & fvi.ProductVersion)
        sb.AppendLine("LegalCopyright:  " & fvi.LegalCopyright)

        Return sb.ToString
    End Function


    Private Sub Form1_Load(ByVal sender As Object, _
                           ByVal e As EventArgs) _
                           Handles MyBase.Load
        Dim ensamblado As System.Reflection.Assembly = _
                System.Reflection.Assembly.GetExecutingAssembly
        txtFichero.Items.Add(ensamblado.Location)

        txtFichero.Items.Add("E:\gsCodigo\Vb5_L\gsCalc\gsCalc.exe")
        txtFichero.Items.Add("C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll")
        txtFichero.Items.Add("C:\Windows\winhlp32.exe")
        txtFichero.Items.Add("C:\Windows\Microsoft.NET\Framework\v3.5\vbc.exe")
        txtFichero.Items.Add("C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe")

        txtFichero.SelectedIndex = 0
    End Sub


    Private Sub Form1_DragEnter(ByVal sender As Object, _
                                ByVal e As DragEventArgs) _
                                Handles MyBase.DragEnter, txtFichero.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub

    Private Sub Form1_DragDrop(ByVal sender As Object, _
                               ByVal e As DragEventArgs) _
                               Handles MyBase.DragDrop, txtFichero.DragDrop
        If e.Data.GetDataPresent("FileDrop") Then
            txtFichero.Text = CType(e.Data.GetData("FileDrop", True), String())(0)
        End If
    End Sub
End Class
Francisco J. Alegr铆a P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 408
Joined: Sun Aug 13, 2006 05:38 AM

Re: Versi贸n del ejecutable

Posted: Tue Apr 28, 2015 03:51 AM

Antonio. Disculpa mi ignorancia en C pero 驴como lo puedo integrar a FW/harbour?

Francisco. Esperemos que alguien pueda, porque yo no pude :(

Saludos

Quique
Posts: 1380
Joined: Fri Oct 14, 2005 01:28 PM

Re: Versi贸n del ejecutable

Posted: Tue Apr 28, 2015 11:09 AM
Quique;
Se me pas贸 comentarte que la funci贸n la uso con xHarbour Harbour Compiler build 1.2.1 (SimpLex) (Rev. 9421) y FWH 12.04

Ahora bien lo acabo de compilar (sin tocar nada porque de C desconozco) con Harbour 3.2.0dev (r1406161338) y FWH 12.04
y solo me sale el siguiente warning:
--------------------Configuraci贸n: pru32 - Debug--------------------
Harbour 3.2.0dev (r1406161338)
Copyright (c) 1999-2014, http://harbour-project.org/
Borland C++ 5.82 for Win32 Copyright (c) 1993, 2005 Borland
FileVer.c:
Warning W8075 d:\\MIHARB~1\\TEmege\\Sources\\FileVer.prg 27: Suspicious pointer conversion in function HB_FUN_GETFILEVERSIONINFO
Turbo Incremental Link 5.69 Copyright (c) 1997-2005 Borland
filever.exe - 0 error(es), 1 advertencia(s)

Por lo que me muestra versi贸n y dem谩s
Quiz谩s si uds. saben me puedan indicar como evitar este warning

Haciendo boton derecho sobre el icono del ejecutable e ingresando en Detalle (W7) obviamente tambien se lee los datos enviados
Resistencia - "Ciudad de las Esculturas"

Chaco - Argentina
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM

Re: Versi贸n del ejecutable

Posted: Tue Apr 28, 2015 12:33 PM
Code (fw): Select all Collapse
1 VERSIONINFO LOADONCALL MOVEABLE DISCARDABLE IMPURE
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x0
FILEFLAGS 0x0
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
FILESUBTYPE VFT2_UNKNOWN
{
聽BLOCK "StringFileInfo"
聽{
聽 BLOCK "040904E4"
聽 {
聽 聽VALUE "Comments", 聽 聽"Sistema Desenvolvido Pela Empresa TAL - <!-- m --><a class="postlink" href="http://www.empresatal.com.br">http://www.empresatal.com.br</a><!-- m --> \0"
聽 聽VALUE "CompanyName", 聽 "Sistema Desenvolvido Pela Empresa TAL - <!-- m --><a class="postlink" href="http://www.empresatal.com.br">http://www.empresatal.com.br</a><!-- m --> \0"
聽 聽VALUE "FileDescription", "NOMBRE DEL SISTEMA\0"
聽 聽VALUE "FileVersion", 聽 "1.0000\0"
聽 聽VALUE "InternalName", 聽"Proyecto TAL\0"
聽 聽VALUE "LegalCopyright", "Empresa Inform谩tica Ltda\0"
聽 聽VALUE "LegalTrademarks", "NOMBRE SISTEMA / SISTEMA\0"
聽 聽VALUE "OriginalFilename", "NOMBRE_EXE.EXE\0"
聽 聽VALUE "ProductName", 聽 "NOMBRE DEL SISTEMA\0"
聽 聽VALUE "ProductVersion", "1.0000\0"
聽 }
聽}
聽BLOCK "VarFileInfo"
聽{
聽 VALUE "Translation", 0x416, 0x4B0
聽}
}


Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion