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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving ProductVersion from stringtable

Status
Not open for further replies.

john0532

Programmer
Jul 2, 2002
27
US
How do you get the ProductVersion, FileVersion, etc. from the string table?
 
Use the FileVersion API's, see GetFileVersionInfo(..)

-pete
 
I've created a little object wrapper for this; I hope it wraps correctly :)

First the Header file:


// Declarations for Version from Version Resource class
// Written by Frank Solomon 2000
//
#ifndef __ver_h
#define __ver_h

#include <windows.h>

namespace fss {

class VersionResource {
UINT VLen;
LPVOID VBuf;
char VString[1024];
char VCopyright[1024];
char VProduct[1024];
public:
VersionResource();
const char *c_str() const;
const char *copyright() const;
const char *product() const;
const char *version() const;
};

} // namespace fss

#endif //__ver_h

Then the .cpp file:

// Definitions for Version from Version Resource class
// Written by Frank Solomon 2000
//

#include &quot;ver.h&quot;

namespace fss {

VersionResource::VersionResource() {
HRSRC hrV = FindResource(NULL,&quot;#1&quot;,RT_VERSION);
if(hrV == NULL) {
throw;
} else {
HGLOBAL hgrV = LoadResource(NULL,hrV);
if(hgrV == NULL) {
throw;
} else {
LPVOID pV = LockResource(hgrV);
if(VerQueryValue(pV,&quot;\\StringFileInfo\\040904b0\\FileVersion&quot;,&VBuf,&VLen)) {
if(VLen > 0 && VLen < 1024) {
wsprintf(VString,&quot;%s&quot;,VBuf);
} else {
throw;
}
}
if(VerQueryValue(pV,&quot;\\StringFileInfo\\040904b0\\LegalCopyright&quot;,&VBuf,&VLen)) {
if(VLen > 0 && VLen < 1024) {
wsprintf(VCopyright,&quot;%s&quot;,VBuf);
} else {
throw;
}
}
if(VerQueryValue(pV,&quot;\\StringFileInfo\\040904b0\\ProductName&quot;,&VBuf,&VLen)) {
if(VLen > 0 && VLen < 1024) {
wsprintf(VProduct,&quot;%s&quot;,VBuf);
} else {
throw;
}
}
FreeResource(hgrV);
}
}
}

const char *VersionResource::c_str() const {
return (const char *)VString;
}

const char *VersionResource::version() const {
return (const char *)VString;
}

const char *VersionResource::copyright() const {
return (const char *)VCopyright;
}

const char *VersionResource::product() const {
return (const char *)VProduct;
}
}

And Finally here's an example of how it's used (vermain.cpp):

//Demo of VersionResource Object
//Be sure to add version.dll to the linker input for this project
//Also be sure to link in a version resource!!!
#include <iostream>
#include &quot;ver.h&quot;

using std::cout;
using std::endl;
using fss::VersionResource;

int main(int argc, const char *argv[]) {
VersionResource V;
cout << &quot;The Current version is: &quot; << V.c_str() << endl;
}

Hope that's helpful.

DJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top