Mega Code Archive

 
Categories / Delphi / System
 

How to obtain DLL specific version information

Title: How to obtain DLL-specific version information // DLLVERSIONINFO structure type PDLLVerInfo=^TDLLVersionInfo; TDLLVersionInfo=Record cbSize, // Size of the structure, in bytes. dwMajorVersion, // Major version of the DLL dwMinorVersion, // Minor version of the DLL dwBuildNumber, // Build number of the DLL dwPlatformID: DWord; // Identifies the platform for which the DLL was built end; var DllGetVersion: function(dvi: PDLLVerInfo): PDLLVerInfo; stdcall; function GetDllVersion(DllName: string; var DLLVersionInfo: TDLLVersionInfo): Boolean; var hInstDll: THandle; p: pDLLVerInfo; begin Result := False; // Get a handle to the DLL module. hInstDll := LoadLibrary(PChar(DllName)); if (hInstDll = 0) then Exit; // Return the address of the specified exported (DLL) function. // Adresse der Dll-Funktion ermitteln @DllGetVersion := GetProcAddress(hInstDll, 'DllGetVersion'); // If the handle is not valid, clean up an exit. // Wenn das Handle ung¨¹ltig ist, wird die Funktion verlassen if (@DllGetVersion) = nil then begin FreeLibrary(hInstDll); Exit; end; new(p); try ZeroMemory(p, SizeOf(p^)); p^.cbSize := SizeOf(p^); // Call the DllGetVersion function DllGetVersion(p); DLLVersionInfo.dwMajorVersion := p^.dwMajorVersion; DLLVersionInfo.dwMinorVersion := p^.dwMinorVersion; @DllGetVersion := nil; Result := True; finally dispose(P); end; // Free the DLL module. FreeLibrary(hInstDll); end; Usage Example to get version info from comctl32.dll procedure TForm1.Button1Click(Sender: TObject); var DLLVersionInfo: TDLLVersionInfo; begin if not GetDllVersion('comctl32.dll',DLLVersionInfo) then begin DLLVersionInfo.dwMajorVersion := 4; DLLVersionInfo.dwMinorVersion := 0; end; with DLLVersionInfo do ShowMessage(Format('ComCtl Version: %d.%d / Build: %d',[dwMajorVersion, dwMinorVersion, dwBuildNumber])) end;