Using DllGetVersion to Determine the Version Number

This article describes how to determine the version of the running Windows Shell or common controls DLLs (Comctl32.dll, Shell32.dll, and Shlwapi.dll). The function GetDllVersion calls the exported DllGetVersion and is a Delphi translation of the example on MSDN (see Shell and Common Controls Versions ).

 const   ComCtlVersionWin2k = $00050051;  // 5.81, Windows 2000 and Windows Me   ComCtlVersionWinXP_Classic = $00050052;  // 5.82, Windows XP classic mode   ComCtlVersionWinXP = $00060000;  // 6.0, Windows XP  type   pDLLVERSIONINFO = ^DLLVERSIONINFO;   DLLVERSIONINFO = packed record     cbSize: DWORD;     dwMajorVersion: DWORD;     dwMinorVersion: DWORD;     dwBuildNumber: DWORD;     dwPlatformID: DWORD;   end;    DLLGETVERSIONPROC = function(pdvi: pDLLVERSIONINFO): HRESULT stdcall;  function GetDllVersion(szDllName: PChar): Cardinal; var   hinstDll: HINST;   dwVersion: DWORD;   hr: HRESULT;   DllGetVersion: DLLGETVERSIONPROC;   dvi: DLLVERSIONINFO; begin   dwVersion := 0;    (* For security purposes, LoadLibrary should be provided with a      fully-qualified path to the DLL. The lpszDllName variable should be      tested to ensure that it is a fully qualified path before it is used. *)   hinstDll := LoadLibrary(szDllName);    if (hinstDll > 0) then   begin     @DllGetVersion := GetProcAddress(hinstDll, 'DllGetVersion');      (* Because some DLLs might not implement this function, you     must test for it explicitly. Depending on the particular     DLL, the lack of a DllGetVersion function can be a useful     indicator of the version. *)      if Assigned(DllGetVersion) then     begin       ZeroMemory(@dvi, sizeof(dvi));       dvi.cbSize := sizeof(dvi);       hr := DllGetVersion(@dvi);       if Succeeded(hr)         then dwVersion := MakeLong(dvi.dwMinorVersion, dvi.dwMajorVersion);     end;      FreeLibrary(hinstDll);   end;   Result := dwVersion; end; 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *