use shell function: Implemented by many of the Windows shell DLLs to allow applications to obtain DLL-specific version information.HRESULT CALLBACK DllGetVersion( DLLVERSIONINFO *pdvi ); //sample code BOOL CDLLVersion::GetDLLVersion (LPSTR szDLLFileName, DWORD &dwMajor, DWORD &dwMinor, DWORD &dwBuildNumber) { HINSTANCE hDllInst; // Instance of loaded DLL char szFileName [_MAX_PATH]; // Temp file nameBOOL bRes = TRUE; // Result lstrcpy (szFileName, szDLLFileName); // Save a file name copy for the loading
hDllInst = LoadLibrary(TEXT(szFileName)); //load the DLL if(hDllInst) // Could successfully load the DLL { DLLGETVERSIONPROC pDllGetVersion; /* You must get this function explicitly because earlier versions of the DLL don't implement this function. That makes the lack of implementation of the function a version er in itself. */ pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hDllInst, TEXT("DllGetVersion"));
if(pDllGetVersion) // DLL supports version retrieval function { DLLVERSIONINFO dvi; ZeroMemory(&dvi, sizeof(dvi)); dvi.cbSize = sizeof(dvi); HRESULT hr = (*pDllGetVersion)(&dvi); if(SUCCEEDED(hr)) // Finally, the version is at our hands { dwMajor = dvi.dwMajorVersion; dwMinor = dvi.dwMinorVersion; dwBuildNumber = dvi.dwBuildNumber; } else bRes = FALSE; // Failure } else // GetProcAddress failed, the DLL cannot tell its version bRes = FALSE; // Failure FreeLibrary(hDllInst); // Release DLL } else bRes = FALSE; // DLL could not be loaded if (!bRes) // Cannot read DLL version the nice way { for(int iDir = WIN_DIR; iDir <= NO_DIR; iDir++) // loop for each possible directory { lstrcpy (szFileName, szDLLFileName); // Save a file name copy for the loading bRes = CheckFileVersion (szFileName, iDir, dwMajor, dwMinor, dwBuildNumber); // Try the ugly way if(bRes) break; }; return bRes; } else return TRUE; }
Implemented by many of the Windows shell DLLs to allow applications to obtain DLL-specific version information.HRESULT CALLBACK DllGetVersion(
DLLVERSIONINFO *pdvi
);
//sample code
BOOL CDLLVersion::GetDLLVersion (LPSTR szDLLFileName,
DWORD &dwMajor, DWORD &dwMinor, DWORD &dwBuildNumber)
{
HINSTANCE hDllInst; // Instance of loaded DLL
char szFileName [_MAX_PATH]; // Temp file nameBOOL bRes = TRUE; // Result
lstrcpy (szFileName, szDLLFileName); // Save a file name copy for the loading
hDllInst = LoadLibrary(TEXT(szFileName)); //load the DLL
if(hDllInst) // Could successfully load the DLL
{
DLLGETVERSIONPROC pDllGetVersion;
/*
You must get this function explicitly because earlier versions of the DLL
don't implement this function. That makes the lack of implementation of the
function a version er in itself.
*/
pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hDllInst,
TEXT("DllGetVersion"));
if(pDllGetVersion) // DLL supports version retrieval function
{
DLLVERSIONINFO dvi; ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
HRESULT hr = (*pDllGetVersion)(&dvi); if(SUCCEEDED(hr)) // Finally, the version is at our hands
{
dwMajor = dvi.dwMajorVersion;
dwMinor = dvi.dwMinorVersion;
dwBuildNumber = dvi.dwBuildNumber;
}
else
bRes = FALSE; // Failure
}
else // GetProcAddress failed, the DLL cannot tell its version
bRes = FALSE; // Failure FreeLibrary(hDllInst); // Release DLL
}
else
bRes = FALSE; // DLL could not be loaded if (!bRes) // Cannot read DLL version the nice way
{
for(int iDir = WIN_DIR; iDir <= NO_DIR; iDir++) // loop for each possible directory
{
lstrcpy (szFileName, szDLLFileName); // Save a file name copy for the loading
bRes = CheckFileVersion (szFileName, iDir,
dwMajor, dwMinor, dwBuildNumber); // Try the ugly way
if(bRes)
break;
};
return bRes;
}
else
return TRUE;
}
GetCommandLine