Class Wrapper to Retrieve Module Information (VS_VERSION_INFO Resource)

Environment:Win 95, Win 98 SE, NT4 SP3, Win 2000

Yet another class to get all the VS_VERSION_INFO resource information you need, from any module!

Many people have requested this code in response to reading some of my posts – well, here it is. You can optionally specify language id and code page, to query language specific VS_VERSION_INFO elements of the block – very helpful. You have the option of querying your own module information (many people have been confused as to how to do this). The code to get your own module name, I have included in a separate class (CVFXGetModuleName) so that you can use it separately (for whatever reason). The retrieved values, are also returned in a separate class (CVFXVersionRes) making it easy to pass the retrieved information around as an object.

Feel free to improve upon it if you find it lacking in any area – enjoy!

//—————————————————————–
// Here are two examples of implementing and using these classes
//—————————————————————–
//
// Make sure to include the following source files into your project:
//
// – VFXGetModuleName.h
// – VFXGetModuleName.cpp
//
// – VFXPointer.h
// – VFXPointer.cpp
//
// – VFXVersionInfo.h
// – VFXVersionInfo.cpp
//
// …Then, #include “VFXVersionInfo.h” in the module you will use
// the class
//
// All the information you will need will be returned in the
// CVFXVersionRes class object pass to the
// CVFXVersionInfo::GetVersionInfo(CVFXVersionRes&) member
//

//—————————————————————–
// Example to get your OWN module’s version information
//—————————————————————–
bool CMySillyClass::GetThisModuleVerInfo(CString& sVersion)
{
sVersion.Empty();

CVFXVersionRes VersionRes;
CVFXVersionInfo VersionInfo;

// Note: passing NULL as a module name here will return the
// version information for the current module

if(VersionInfo.GetVersionInfo(VersionRes))
{
// Display the whole VS_VERSION_INFO block in a message box
VersionRes.Display();

// Get the file version to return
sVersion = VersionRes.m_sFileVersion;

return true;
}
else
{
AfxMessageBox(“Module not found, or version info not found”,
MB_OK | MB_ICONERROR);
}

return false;
}

//—————————————————————–
// Example to get your ANOTHER module’s version information
//—————————————————————–

bool CMySillyClass::GetAnotherModuleVerInfo(const CString& sModName,
CString& sVersion)
{
sVersion.Empty();

if(sModName.IsEmpty())
return false;

CVFXVersionRes VersionRes;
CVFXVersionInfo VersionInfo;

// Note: passed a module name here, the default (NULL) will
// return the version information for the current module

if(VersionInfo.GetVersionInfo(VersionRes, sModName))
{
// Display the whole VS_VERSION_INFO block in a message box
VersionRes.Display();

// Get the file version to return

sVersion = VersionRes.m_sFileVersion;

return true;
}
else
{
AfxMessageBox(“Module not found, or version info not found”,
MB_OK | MB_ICONERROR);
}

return false;
}

//—————————————————————–
// Example to get your OWN module’s version information (UK block)
//—————————————————————–

bool CMySillyClass::GetThisModuleVerInfoUKBlock(CString& sVersion)
{
sVersion.Empty();

CVFXVersionRes VersionRes;
// Notice passing codepage and language id specific –
// default is English US!

CVFXVersionInfo VersionInfo(ENGLISH_UNICODE_UK,
MAKELANGID(LANG_ENGLISH,
SUBLANG_ENGLISH_UK));

// Note: passing NULL as a module name here will return the
// version information for the current module

if(VersionInfo.GetVersionInfo(VersionRes))
{
// Display the whole VS_VERSION_INFO block in a message box
VersionRes.Display();

// Get the file version to return
sVersion = VersionRes.m_sFileVersion;

return true;
}
else
{
AfxMessageBox(“Module not found, or version info not found”,
MB_OK | MB_ICONERROR);
}

return false;
}

Downloads

Download demo project – 12 Kb

Download source – 20 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read