检测DLL的版本号如何通过你的MFC应用程序检测DLL的版本信息。
COMCTL32.DLL versions该DLL负责Windows使用的所有控制。
Windows95首先使用该库,版本号为4.0.Internet Explorer3.x升级它为4.70.Internet Explorer 4.0的版本为4.71.扩展控制(如带检取框的列表视)只在比4.00版以上得到支持。
关于公用控制版本的详细信息可到下列网址获取:/msdn/sdk/inetsdk/help/inet1560.htmUnimodemVUnimodem是一个通过TAPI使用的标准的Modem驱动程序。
modem硬件提供的驱动程序95%以上仅仅是参数文件.Unimodem的32位驱动程序放在Windows系统目录中的UMDN32.dll.最近,微软发布了Voice modems的升级版本,命名为UnimodemV.该版本支持一些新的特点,如:呼叫者ID,特殊的响铃等.该升级版可到如下网址下载:/kb/articles/Q139/3/83.htm原有的Unimodem的版本是UMDM32.DLL 4.00。
UnimodemV用4.10版本替换了该动态链接库。
如何发现一个DLL的版本信息呢?下面类实现了接受DLL版本信息:Class header file:/* For some odd reason, Microsoft published a sample code that uses shlwapi.h(and shlwapi.lib)to tinker file versions.This header file could not be found anywhere !!!Not in Visual C++ 4.2, Visual C++ 5.0 or MSDN versions up to July 97`.So, I just took out the interesting structures from scraps I found and re-defined them here.*/// Remember: You must link version.lib to the project for this class to work !!// 切记:为使该类正常工作,你必须将version.lib链接到你的项目中!!#ifndef _DLL_VERSION_H_#define _DLL_VERSION_H_#ifndef DLLVERSIONINFOtypedefstruct _DllVersionInfo{DWORD cbSize;DWORD dwMajorVersion;DWORD dwMinorVersion;DWORD dwBuildNumber;DWORD dwPlatformID;}DLLVERSIONINFO;#endif#ifndef DLLGETVERSIONPROCtypedefint (FAR WINAPI *DLLGETVERSIONPROC) (DLLVERSIONINFO *);#endifclassCDLLVersion{typedefenum { WIN_DIR, // Windows directory (e.g.: "C:\Windows\")SYS_DIR, // Windows system directory (e.g.:"C:\Windows\System")CUR_DIR, // Current directory (e.g.: ".")NO_DIR} // No directory (path in file name) FileLocationType; // Possible ways to add a path prefix to a filepublic:CDLLVersion (LPSTR szDLLFileName) :m_dwMajor (0),m_dwMinor (0),m_dwBuild (0){m_bValid = GetDLLVersion (szDLLFileName, m_dwMajor, m_dwMinor,m_dwBuild);}virtual ~CDLLVersion () {};DWORD GetMajorVersion (){returnm_dwMajor;}DWORD GetMinorVersion (){returnm_dwMinor;}DWORD GetBuildNumber (){returnm_dwBuild;}BOOL IsValid (){returnm_bValid;}private:BOOL GetDLLVersion (LPSTR szDLLFileName,DWORD &dwMajor, DWORD &dwMinor, DWORD&dwBuildNumber);BOOL CheckFileVersion (LPSTR szFileName, FileLocationTypeFileLoc, DWORD &dwMajor, DWORD &dwMinor, DWORD&dwBuildNumber);BOOL ParseVersionString (LPSTR lpVersion,DWORD &dwMajor, DWORD &dwMinor, DWORD&dwBuildNumber);BOOL FixFilePath (char * szFileName, FileLocationTypeFileLoc);DWORD m_dwMajor, // Major version numberm_dwMinor, // Minor version numberm_dwBuild; // Build numberBOOL m_bValid; // Is the DLL version information valid ? };#endif这里是实现部分:#include "DLLVersion.h"/**********************************************************Function: GetDLLVersionPurpose: Retrieves DLL major version, minor version and build numbersInput: DLL file nameReference to Major numberReference to Minor numberReference to Build numberOutput: TRUE only if successfulRemarks: This function first tries to get the DLL version the nice way,that is, call the DllGetVersion function in the DLL.If this fails, it tries to located the DLL file in the file system,read the file information block and retrieve the file version.********************************************************************* *******/BOOL CDLLVersion::GetDLLVersion (LPSTR szDLLFileName,DWORD &dwMajor, DWORD &dwMinor, DWORD &dwBuildNumber){HINSTANCE hDllInst; // Instance of loaded DLLcharszFileName [_MAX_PATH]; // Temp file nameBOOL bRes = TRUE; // Resultlstrcpy (szFileName, szDLLFileName); // Save a file name copy for the loadinghDllInst = LoadLibrary(TEXT(szFileName)); //load the DLLif(hDllInst) { // Could successfully load the DLLDLLGETVERSIONPROC pDllGetVersion;/*You must get this function explicitly because earlier versions of the DLLdon't implement this function. That makes the lack of implementation of thefunction a version marker in itself.*/pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hDllInst,TEXT("DllGetVersion"));if(pDllGetVersion) { // DLL supports version retrieval functionDLLVERSIONINFO dvi;ZeroMemory(&dvi, sizeof(dvi));dvi.cbSize = sizeof(dvi);HRESULT hr = (*pDllGetVersion)(&dvi);if(SUCCEEDED(hr)) { // Finally, the version is at our handsdwMajor = dvi.dwMajorVersion;dwMinor = dvi.dwMinorVersion;dwBuildNumber = dvi.dwBuildNumber;} elsebRes = FALSE; // Failure} else // GetProcAddress failed, the DLL cannot tell its version bRes = FALSE; // FailureFreeLibrary(hDllInst); // Release DLL} elsebRes = FALSE; // DLL could not be loadedif (!bRes) // Cannot read DLL version the nice way returnCheckFileVersion (szFileName, SYS_DIR,dwMajor, dwMinor, dwBuildNumber); // Try the ugly wayelsereturn TRUE;}/******************************************************************** *******Function: CheckFileVersionPurpose: Check the version information of a given fileInput: File nameFile location (Windows dir, System dir, Current dir or none)Reference to Major numberReference to Minor numberReference to Build numberOutput: TRUE only if successfulRemarks: Trashes original file name********************************************************************* *******/BOOL CDLLVersion::CheckFileVersion (LPSTR szFileName, FileLocationTypeFileLoc,DWORD &dwMajor, DWORD &dwMinor, DWORD &dwBuildNumber){LPSTR lpVersion; // String pointer to 'version' textUINT uVersionLen;DWORD dwVerHnd=0; // An 'ignored' parameter, always '0'FixFilePath (szFileName, FileLoc); // Add necessary path prefix to file nameDWORD dwVerInfoSize = GetFileVersionInfoSize (szFileName,&dwVerHnd);if (!dwVerInfoSize) // Cannot reach the DLL filereturn FALSE;LPSTR lpstrVffInfo =(LPSTR) malloc (dwVerInfoSize); // Alloc memory for file infoif (lpstrVffInfo == NULL)return FALSE; // Allocation failed// Try to get the infoif (!GetFileVersionInfo(szFileName, dwVerHnd, dwVerInfoSize, lpstrVffInfo)) {free (lpstrVffInfo);return FALSE; // Cannot read the file information -// wierd, since we could read the information size}/* The below 'hex' value looks a little confusing, butessentially what it is, is the hexidecimal representationof a couple different values that represent the languageand character set that we are wanting string values for.040904E4 is a very common one, because it means:US English, Windows MultiLingualcharacterset Or to pull it all apart:04------ = SUBLANG_ENGLISH_USA--09---- = LANG_ENGLISH----04E4 = 1252 = Codepage for Windows:Multilingual */if (!VerQueryValue ( lpstrVffInfo,(LPSTR)(TEXT("\\StringFileInfo\\040904E4\\FileVersion")),(LPVOID *)&lpVersion, (UINT *)&uVersionLen)) {free (lpstrVffInfo);return FALSE; // Query was unsuccessful}// Now we have a string that looks like this :// "MajorVersion.MinorVersion.BuildNumber", so let's parse itBOOL bRes = ParseVersionString (lpVersion, dwMajor, dwMinor, dwBuildNumber);free (lpstrVffInfo);returnbRes;}/******************************************************************** *******Function: ParseVersionStringPurpose: Parse version information string into 3 different numbersInput: The version string formatted as"MajorVersion.MinorVersion.BuildNumber"Reference to Major numberReference to Minor numberReference to Build numberOutput: TRUE only if successfulRemarks:********************************************************************* *******/BOOL CDLLVersion::ParseVersionString (LPSTR lpVersion,DWORD &dwMajor, DWORD &dwMinor, DWORD &dwBuildNumber){// Get first token (Major version number)LPSTR token = strtok(lpVersion, TEXT (".") );if (token == NULL) // End of stringreturn FALSE; // String ended prematurelydwMajor = atoi (token);token = strtok (NULL, TEXT (".")); // Get second token (Minor version number)if (token == NULL) // End of stringreturn FALSE; // String ended prematurelydwMinor = atoi (token);token = strtok (NULL, TEXT (".")); // Get third token (Build number) if (token == NULL) // End of stringreturn FALSE; // String ended prematurelydwBuildNumber = atoi (token);return TRUE;}/******************************************************************** *******Function: FixFilePathPurpose: Adds the correct path string to a file name according to given file locationInput: Original file nameFile location (Windows dir, System dir, Current dir or none)Output: TRUE only if successfulRemarks: Trashes original file name********************************************************************* *******/BOOL CDLLVersion::FixFilePath (char * szFileName, FileLocationTypeFileLoc){charszPathStr [_MAX_PATH]; // Holds path prefixswitch (FileLoc) {case WIN_DIR:// Get the name of the windows directoryif (GetWindowsDirectory (szPathStr, _MAX_PATH) == 0)return FALSE; // Cannot get windows directorybreak;case SYS_DIR:// Get the name of the windows SYSTEM directoryif (GetSystemDirectory (szPathStr, _MAX_PATH) == 0)return FALSE; // Cannot get system directorybreak;case CUR_DIR:// Get the name of the current directoryif (GetCurrentDirectory (_MAX_PATH, szPathStr) == 0)return FALSE; // Cannot get current directorybreak;case NO_DIR:lstrcpy (szPathStr,"");break;default:return FALSE;}lstrcat (szPathStr, _T("\\")); lstrcat (szPathStr, szFileName); lstrcpy (szFileName, szPathStr); return TRUE;}。