Board index » cppbuilder » Read application version in code

Read application version in code


2004-08-11 11:05:04 PM
cppbuilder29
Is there a way to access the version number I have given my app
in the Project Options ->Version Info page? What I'd like to
do is have the app automatically change the version number on my
"About" form so I don't have to remember to do it manually.
Thanks much,
-Terry
 
 

Re:Read application version in code

TerryC wrote:
Quote
Is there a way to access the version number I have given my app
in the Project Options ->Version Info page?
This is what we use:
DWORD dumbo;
DWORD versionInfoSize=GetFileVersionInfoSize(
Application->ExeName.c_str(),
&dumbo );
if( versionInfoSize )
{
BYTE *versionInfo=new BYTE[ versionInfoSize ];
if( GetFileVersionInfo( Application->ExeName.c_str(),
dumbo,
versionInfoSize,
versionInfo ) )
{
AnsiString tmpLabelString="";
char *versionInfoBuf=NULL;
unsigned int versionInfoLen=0;
// NB : 080904E4 is language specific. First four digits
// taken from Options/Version.
// First lets build the file information
if( VerQueryValue( versionInfo,
"\\StringFileInfo\\080904E4\\FileDescription",
&( ( void* )versionInfoBuf ),
&versionInfoLen ) )
{
char *fileDescStr=new char[ versionInfoLen+1 ];
strncpy( fileDescStr, versionInfoBuf, versionInfoLen );
*( fileDescStr+versionInfoLen )='\0';
if( VerQueryValue( versionInfo,
"\\StringFileInfo\\080904E4\\FileVersion",
&( ( void* )versionInfoBuf ),
&versionInfoLen ) )
{
char *fileVerStr=new char[ versionInfoLen+1 ];
strncpy( fileVerStr, versionInfoBuf, versionInfoLen );
*( fileVerStr+versionInfoLen )='\0';
{
// <property>+= doesn't work :(
tmpLabelString=fileDescStr;
tmpLabelString+=" v";
tmpLabelString+=fileVerStr;
FormAboutBox_VersionString=fileVerStr;
}
KillAry( fileVerStr );
}
KillAry( fileDescStr );
}
// Grab the copyright information
char * copyrightStr=NULL;
if( VerQueryValue( versionInfo,
"\\StringFileInfo\\080904E4\\LegalCopyright",
&( ( void* )versionInfoBuf ),
&versionInfoLen ) )
{
copyrightStr=new char[ versionInfoLen+1 ];
strncpy( copyrightStr, versionInfoBuf, versionInfoLen );
*( copyrightStr+versionInfoLen )='\0';
{
// <property>+= doesn't work :(
VersionLabel->Caption=tmpLabelString+" "+copyrightStr;
}
}
// Now lets build the product information
if( VerQueryValue( versionInfo,
"\\StringFileInfo\\080904E4\\ProductName",
&( ( void* )versionInfoBuf ),
&versionInfoLen ) )
{
char *prodDescStr=new char[ versionInfoLen+1 ];
strncpy( prodDescStr, versionInfoBuf, versionInfoLen );
*( prodDescStr+versionInfoLen )='\0';
if( VerQueryValue( versionInfo,
"\\StringFileInfo\\080904E4\\ProductVersion",
&( ( void* )versionInfoBuf ),
&versionInfoLen ) )
{
char *prodVerStr=new char[ versionInfoLen+1 ];
strncpy( prodVerStr, versionInfoBuf, versionInfoLen );
*( prodVerStr+versionInfoLen )='\0';
{
// <property>+= doesn't work :(
tmpLabelString=prodDescStr;
tmpLabelString+=" v";
tmpLabelString+=prodVerStr;
VFSVersionLabel->Caption=tmpLabelString;
}
KillAry(prodVerStr);
}
KillAry(prodDescStr);
}
VFSCopyrightLabel->Caption=copyrightStr;
KillAry(copyrightStr);
}
KillAry( versionInfo );
}
KillAry() is a template that calls delete[]
Quote
What I'd like to
do is have the app automatically change the version number on my
"About" form so I don't have to remember to do it manually.
Hmmm. BCB5 and later are supposed to increment the build number for you
(but often don't). Presumbably there is a way to set this information
but I can't find it.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:Read application version in code

"Andrue Cope [TeamB]" < XXXX@XXXXX.COM >wrote:
[...]
Quote
This is what we use:
[...]
Many thanks! I massaged the code you posted to fit what I'm
doing, and it works perfectly.
Quote
Hmmm. BCB5 and later are supposed to increment the build
number for you (but often don't). Presumbably there is a way
to set this information but I can't find it.
That isn't necessary. The build number is behaving correctly;
I only needed to automatically update a few TLabels on my About
form when I change things in Options->Version Info.
Great stuff!
-Terry
 

{smallsort}

Re:Read application version in code

TerryC wrote:
Quote
Many thanks! I massaged the code you posted to fit what I'm
doing, and it works perfectly.
Great. I should probably massage it as well. It's very um..rustic :)
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:Read application version in code

Quote
Hmmm. BCB5 and later are supposed to increment the build number for you
(but often don't). Presumbably there is a way to set this information
but I can't find it.
for me they always increment .... but with build ... not with compilation ;)