🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages Started by Kris Sun, 06 Aug 2006 11:04
Problem extracting version information from EXE
#3226
Author: Kris
Date: Sun, 06 Aug 2006 11:04
77 lines
3151 bytes
Following version information is built with my EXE :

FileVersion : 51.62.73.84
ProductVersion : 3.4.5.6

Right-clicking in Explorer on the EXE and selecting the 2nd tab
(Version-tab) confirms that both these values are indeed present in
the EXE.

However, when I'm trying to retrieve this information myself I get
this output :

dwFileVersionMS...=0x33003e
dwFileVersionLS...=0x490055
 
dwProductVersionMS=0x33003e
dwProductVersionLS=0x490055
 
FileVersion=[51.62.73.85]
ProductVersion=[51.62.73.85]

For some strange reason my code results in ProductVersion having the
same value as FileVersion. Does anybody have any ideas on why this is
happening ?

//--------------------------------------------------------------------------
-
String Test::GetVersionInformationResourceField(String FilePathName) {
  String FileVersion,ProductVersion;
  DWORD Dummy;
  DWORD InfoSize=GetFileVersionInfoSize(FilePathName.c_str(),&Dummy);
  char *Buffer=new char[InfoSize];
  if (GetFileVersionInfo(FilePathName.c_str(),0,InfoSize,Buffer))
  {
    unsigned int BufferLength;
    VS_FIXEDFILEINFO *VersionInfo;
    if (VerQueryValue(Buffer,"\\",(void**)&VersionInfo,&BufferLength))
    {
 
Form1->DText("dwFileVersionMS...=0x%04x",VersionInfo->dwFileVersionMS);
 
Form1->DText("dwFileVersionLS...=0x%04x",VersionInfo->dwFileVersionLS);
      Form1->DText(" ");
 
Form1->DText("dwProductVersionMS=0x%04x",VersionInfo->dwProductVersionMS
Form1->);
 
Form1->DText("dwProductVersionLS=0x%04x",VersionInfo->dwProductVersionLS
Form1->);
      Form1->DText(" ");

      FileVersion.printf("%d.%d.%d.%d",
 
HIWORD(VersionInfo->dwFileVersionMS),LOWORD(VersionInfo->dwFileVersionMS),
 
HIWORD(VersionInfo->dwFileVersionLS),LOWORD(VersionInfo->dwFileVersionLS));
      Form1->DText("FileVersion=[%s]",FileVersion);

      ProductVersion.printf("%d.%d.%d.%d",
 
HIWORD(VersionInfo->dwProductVersionMS),LOWORD(VersionInfo->dwProductVersion
MS),
 
HIWORD(VersionInfo->dwProductVersionLS),LOWORD(VersionInfo->dwProductVersion
LS));
      Form1->DText("ProductVersion=[%s]",FileVersion);
      Form1->DText(" ");
    }
  }

  delete[] Buffer;

  // return FileVersion;
  return ProductVersion;
}
//--------------------------------------------------------------------------
-
Re: Problem extracting version information from EXE
#3227
Author: JD
Date: Sun, 06 Aug 2006 11:39
104 lines
5695 bytes
Kris <test@test.com> wrote:
>

Try this:

//-------------------------------------------------------------
#ifndef VerInfoH
#define VerInfoH
//-------------------------------------------------------------
struct TVersionInformation
{
    private:
        char *Buffer;
    public:
        bool Available;
        AnsiString CompanyName;
        AnsiString FileDescription;
        AnsiString FileVersion;
        AnsiString InternalName;
        AnsiString LegalCopyright;
        AnsiString LegalTrademarks;
        AnsiString OriginalFilename;
        AnsiString ProductName;
        AnsiString ProductVersion;
        AnsiString Comments;
    TVersionInformation()
    {
        Buffer = NULL;
        Available        = false;
        CompanyName      = "";
        FileDescription  = "";
        FileVersion      = "";
        InternalName     = "";
        LegalCopyright   = "";
        LegalTrademarks  = "";
        OriginalFilename = "";
        ProductName      = "";
        ProductVersion   = "";
        Comments         = "";

        DWORD Handle, Size = ::GetFileVersionInfoSize( Application->ExeName.c_str(), &Handle );
        if( Size )
          {
              UINT Length;
              LPVOID lpBuffer;
              unsigned short *LangCharSet;
              Buffer = new char[ Size ];
              LPVOID pBlock = (LPVOID) Buffer;
              if( ::GetFileVersionInfo( Application->ExeName.c_str(), Handle, Size, pBlock ) )
                {
                    if( ::VerQueryValue( pBlock, "\\VarFileInfo\\Translation", (void **)&LangCharSet, &Length ) )
                      {
                          AnsiString Prefix;
                          Prefix.sprintf("\\StringFileInfo\\%04x%04x\\", LangCharSet[0], LangCharSet[1] );
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "CompanyName" ).c_str(),      &lpBuffer, &Length ) ) CompanyName      = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "FileDescription" ).c_str(),  &lpBuffer, &Length ) ) FileDescription  = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "FileVersion" ).c_str(),      &lpBuffer, &Length ) ) FileVersion      = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "InternalName" ).c_str(),     &lpBuffer, &Length ) ) InternalName     = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "LegalCopyright" ).c_str(),   &lpBuffer, &Length ) ) LegalCopyright   = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "LegalTrademarks" ).c_str(),  &lpBuffer, &Length ) ) LegalTrademarks  = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "OriginalFilename" ).c_str(), &lpBuffer, &Length ) ) OriginalFilename = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "ProductName" ).c_str(),      &lpBuffer, &Length ) ) ProductName      = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "ProductVersion" ).c_str(),   &lpBuffer, &Length ) ) ProductVersion   = (char *) lpBuffer;
                          if( ::VerQueryValue( pBlock, AnsiString( Prefix + "Comments" ).c_str(),         &lpBuffer, &Length ) ) Comments         = (char *) lpBuffer;
                          Available = true;
                      }
                }
          }
    }
    ~TVersionInformation()
    {
        if( Buffer ) delete [] Buffer;
    }
};
//-------------------------------------------------------------
#endif


usage:

#include "VersionInfo.h"
//-------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TVersionInformation Info;
    if( Info.Available )
      {
          ShowMessage("CompanyName : "      + Info.CompanyName );
          ShowMessage("FileDescription : "  + Info.FileDescription );
          ShowMessage("FileVersion : "      + Info.FileVersion );
          ShowMessage("InternalName : "     + Info.InternalName );
          ShowMessage("LegalCopyright : "   + Info.LegalCopyright );
          ShowMessage("LegalTrademarks : "  + Info.LegalTrademarks );
          ShowMessage("OriginalFilename : " + Info.OriginalFilename );
          ShowMessage("ProductName : "      + Info.ProductName );
          ShowMessage("ProductVersion : "   + Info.ProductVersion );
          ShowMessage("Comments : "         + Info.Comments );
      }
    else ShowMessage("Version Information Not Available.");
}
//-------------------------------------------------------------

~ JD
Re: Problem extracting version information from EXE
#3229
Author: Bob Gonder
Date: Sun, 06 Aug 2006 14:00
15 lines
1458 bytes
Kris wrote:

> 
>FileVersion=[51.62.73.85]
>ProductVersion=[51.62.73.85]
>
>For some strange reason my code results in ProductVersion having the
>same value as FileVersion. Does anybody have any ideas on why this is
>happening ?

Because you are tell it to do so?

>      Form1->DText("FileVersion=[%s]",FileVersion);
>
>      Form1->DText("ProductVersion=[%s]",FileVersion);
Re: Problem extracting version information from EXE
#3230
Author: Kris
Date: Sun, 06 Aug 2006 14:07
5 lines
1063 bytes
On 6 Aug 2006 04:39:23 -0700, "JD" <nospam@nospam.com> wrote:

>Try this:

Thanks. Not sure why my code failed, but yours is working just great.
Re: Problem extracting version information from EXE
#3231
Author: Kris
Date: Sun, 06 Aug 2006 14:10
28 lines
1884 bytes
On Sun, 06 Aug 2006 07:00:05 -0700, Bob Gonder
<notbg@notmindspring.invalid> wrote:

>Because you are tell it to do so?
>
>>      Form1->DText("FileVersion=[%s]",FileVersion);
>>
>>      Form1->DText("ProductVersion=[%s]",FileVersion);

Yes. That was a stupid mistake. However, it isn't the solution to the
problem.

A few lines earlies I printed following fields :

Form1->DText("dwFileVersionMS...=0x%08x",VersionInfo->dwFileVersionMS);
Form1->DText("dwFileVersionLS...=0x%08x",VersionInfo->dwFileVersionLS);
Form1->DText(" ");
Form1->DText("dwProductVersionMS=0x%08x",VersionInfo->dwProductVersionMS);
Form1->DText("dwProductVersionLS=0x%08x",VersionInfo->dwProductVersionLS);

Even though I'm clearly referring to the correct fields they also
report the same info for File and Product :

dwFileVersionMS...=0x0033003e
dwFileVersionLS...=0x00490055
 
dwProductVersionMS=0x0033003e
dwProductVersionLS=0x00490055
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads