whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

48 Visitors Online


 
...obtain DLL-specific version information?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (16):  
     


{***************************
** DllGetVersion Function **

***************************}

{
  Implemented by many of the Microsoft® Windows® Shell dynamic-link libraries (DLLs) to
  allow applications to obtain DLL-specific version information.
}


{
  Using DllGetVersion to Determine the Version Number
  Starting with version 4.71, the Shell and common controls DLLs, among others,
  began exporting DllGetVersion.
  This function can be called by an application to determine which DLL
  version is present on the system. It returns a structure that contains version information.

  Note  DLLs do not necessarily export DllGetVersion. Always test for it
  before attempting to use it.
  For systems earlier than Windows 2000, DllGetVersion returns a DLLVERSIONINFO structure
  that contains the major and minor version numbers, the build number,
  and a platform identifier (ID).
  For Windows 2000 and later systems, DllGetVersion might instead return a
  DLLVERSIONINFO2 structure. This structure contains the QFE number that identifies
  the service pack and provides a more robust way to compare version numbers than DLLVERSIONINFO.
  Because the first member of DLLVERSIONINFO2 is a DLLVERSIONINFO structure,
  the new structure is backward-compatible.
}

// 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: stringvar DLLVersionInfo: TDLLVersionInfo): Boolean;
var
  
hInstDll: THandle;
  p: pDLLVerInfo;
begin
  
Result := False;
  // Get a handle to the DLL module.
  // das Handle zum DLL Modul ermitteln.
  
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
    // Die DllGetVersion() Funktion aufrufen
    
DllGetVersion(p);
    DLLVersionInfo.dwMajorVersion := p^.dwMajorVersion;
    DLLVersionInfo.dwMinorVersion := p^.dwMinorVersion;

    @DllGetVersion := nil;
    Result := True;
  finally
    
dispose(P);
  end;
 // Free the DLL module.
 // Dll wieder freigeben.
 
FreeLibrary(hInstDll);
end;

// Example to get version info from comctl32.dll
// Beispiel, um von comctl32 Versions/Informationen zu erhalten

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;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners