Getting the complete information about DLL/Exe module

Environment: VC++ 6.0

There have been couple of articles which have discussed about how to get file
version info from resource file and getting to know the version of common control
DLL installed on your machine. This article also falls under the same category but
with a slight modification.

Like pervious articles, I am also using the same API function ::GetFileVersionInfo.
But this function doesnt work if the DLL/Exe module is not mapped into the current
processs memory space. To make this function work it becomes very important that the
module should be brought into the memory space of process.

I have tried to build a wrapper class to get complete information about a DLL/Exe
module. The class name ClibraryInfo may not sound very appropriate but some reasons
I couldnt help it. The class has accessor functions for individual piece of information
about module. But each function makes it sure that the protected member functions,
which implement the API calls, are not executed time and again. I have tried to
encapsulate complete information in a data structure DLLINFO. If you dont want to
call each accessor function to get individual function, I have tried to put one
function which returns the information in the DLLINFO data structure and then you
can deal with individual member variables of the structure. You may feel that class
has some unwanted function calls, but the kind of application I was doing I had to
write these functions.

The following piece of code gets the module handle for DLL/Exe for which information
is sought. If first call fails, I am assuming that module is not mapped in the processs
memory. I have loaded the module explicitly in the process. If that also fails, then
failure is reported. But it has been made sure that if the module was explicitly
loaded, it is freed before the process terminates.

hModule = ::GetModuleHandle (m_DllInfo.stDllName);

if (hModule == NULL) {
    // the dll/module may not be mapped into our space. So try to load the module

    hModule = (HMODULE)LoadLibrary (m_DllInfo.stDllName);

    if (hModule == NULL) {
        return (false);
    }

    m_bLibLoaded = true;
}

This project has been compiled on Windows 95 using VC ++ 6 compiler. If you try to
open this project on previous version of VC, you will get couple warnings related to
debug flags set by VC++ 6 compiler. And it is very important that for project to compile,
VERSION.LIB has been included in the link/compile settings.

Download demo project – 24 KB

More by Author

Must Read