Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I get the fileversion info through code? 1

Status
Not open for further replies.

yoink

Programmer
Dec 2, 2001
15
AU
Hi everyone,

I want to display my program's build number (Project Options->Version Info->FileVersion) on a label on a form. Anyone know if this is possible?

Cheers

Andrew
 
It is Possible, and I have a class to perform it, but the code is too much to post it here. Send me an Email or leave your Address here and I will send you the source.


hnd
hasso55@yahoo.com

 
I Decided the source is not to much to post it here:

//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include &quot;gversion.h&quot;

//---------------------------------------------------------------------------
#pragma package(smart_init)
#include <stdio.h>


// swt ist a Variable to distinquish which file (exe or DLL) should be read. exe=0 dll=1

MyVersionInfo::MyVersionInfo(int swt)
{

DWORD fvHandle;
UINT vSize;
char appFName[255];
char *subBlockName = new char[255];

FVData = 0;

if(swt==0)
strcpy(appFName, Application->ExeName.c_str());
if(swt==1)
strcpy(appFName, &quot;userdll.dll&quot;);

OemToChar(appFName, appFName);

DWORD dwSize = ::GetFileVersionInfoSize(appFName, &fvHandle);
if (dwSize)
{
FVData = (void far *) new char[(UINT) dwSize];

if:):GetFileVersionInfo(appFName, fvHandle, dwSize, FVData))
{
strcpy(subBlockName, &quot;\\VarFileInfo\\Translation&quot;);
if (!::VerQueryValue(FVData, subBlockName,(void far* far*)&TransBlock, &vSize))
{
delete[] FVData;
FVData = 0;
}
else
{
*(DWORD *) TransBlock = MAKELONG(HIWORD(*(DWORD *)TransBlock), LOWORD(*(DWORD *)TransBlock));
}
}
}
}


MyVersionInfo::~MyVersionInfo()
{
if (FVData)
delete[] FVData;
}



bool MyVersionInfo::GetProductName(LPSTR& prodName)
{
UINT vSize;
char subBlockName[255];

if(FVData)
{
sprintf(subBlockName, &quot;\\StringFileInfo\\%08lx\\%s&quot;, *(DWORD *) TransBlock, (LPSTR) &quot;ProductName&quot;);
return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*)&prodName, &vSize) : false;
}
else
return(false);
}


bool MyVersionInfo::GetFileVersion(LPSTR& fileVersion)
{
UINT vSize;
char subBlockName[255];

if(FVData)
{
sprintf(subBlockName, &quot;\\StringFileInfo\\%08lx\\%s&quot;, *(DWORD *)TransBlock, (LPSTR) &quot;FileVersion&quot;);
return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*) &fileVersion, &vSize) : false;
}
else
return(false);
}



bool MyVersionInfo::GetProdVersion(LPSTR& prodVersion)
{
UINT vSize;
char subBlockName[255];

if(FVData)
{
sprintf(subBlockName, &quot;\\StringFileInfo\\%08lx\\%s&quot;, *(DWORD *)TransBlock, (LPSTR) &quot;ProductVersion&quot;);
return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*) &prodVersion, &vSize) : false;
}
else
return(false);
}




bool MyVersionInfo::GetCopyright(LPSTR& copyright)
{
UINT vSize;
char subBlockName[255];

if(FVData)
{
sprintf(subBlockName, &quot;\\StringFileInfo\\%08lx\\%s&quot;, *(DWORD *)TransBlock, (LPSTR) &quot;LegalCopyright&quot;);
return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*) &copyright, &vSize) : false;
}
else
return(false);
}

bool MyVersionInfo::GetComment(LPSTR& comment)
{
UINT vSize;
char subBlockName[255];

if(FVData)
{
sprintf(subBlockName, &quot;\\StringFileInfo\\%08lx\\%s&quot;, *(DWORD *)TransBlock, (LPSTR) &quot;FileDescription&quot;);
return FVData ? ::VerQueryValue(FVData, subBlockName,(void far* far*) &comment, &vSize) : false;
}
else
return(false);
}



// VS_FF_DEBUG => Schalter &quot;Fehlersuche&quot;
// VS_FF_INFOINFERRED
// VS_FF_PATCHED
// VS_FF_PRERELEASE => Schalter &quot;Testversion gesetzt&quot;
// VS_FF_PRIVATEBUILD
// VS_FF_SPECIALBUILD

bool MyVersionInfo::GetFlags(LPSTR& flags)
{
UINT vSize;
char subBlockName[255];

if(FVData)
{
sprintf(subBlockName, &quot;\\&quot;);
::VerQueryValue(FVData, subBlockName, (void far* far*) &flags, &vSize);

return(true);
}

return(false);
}

============================================================
//---------------------------------------------------------------------------
#ifndef gversionH
#define gversionH
//---------------------------------------------------------------------------

class MyVersionInfo
{
public:

MyVersionInfo(int swt);
virtual ~MyVersionInfo();

bool GetProductName(LPSTR& prodName);
bool GetFileVersion(LPSTR& fileVersion);
bool GetProdVersion(LPSTR& fileVersion);
bool GetCopyright(LPSTR& copyright);
bool GetComment(LPSTR& comment);
bool GetFlags(LPSTR& flags);

protected:
BYTE far* TransBlock;
void far* FVData;

private:
MyVersionInfo(const MyVersionInfo&);
MyVersionInfo& operator = (const MyVersionInfo&);

};

#endif

============================================================

Calling sequence:


[.....]

LPSTR produkt=0, compstatus=0, flags=0, productversion=0;

MyVersionInfo *versioninfo;
versioninfo = new MyVersionInfo(0);
versioninfo->GetProductName(produkt);
versioninfo->GetFileVersion(compstatus);
versioninfo->GetProdVersion(productversion);
versioninfo->GetFlags(flags);
delete (versioninfo);
[...]

Hope it helps




hnd
hasso55@yahoo.com

 
Borland came with some components for version info. They aren't installed, but I'm fairly sure they work to do what you wanted, although I haven't used them in a while.

You can find the package in:
$(BCB)\Examples\Controls\VersionInfo

Hope it works! Cyprus
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top