Class Wrapper to Retrieve Module Information (VS_VERSION_INFO Resource) | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 7, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.