Board index » delphi » Detecting MSXM4Ldll version

Detecting MSXM4Ldll version


2005-01-26 10:10:48 PM
delphi144
From torrys I found code that seems to be suitable for detecting dll:s
version information. However it dont work if I try to detect MSXML library
version. Can anyone advise me why and if someone has a solution please
inform me.
Thanks to Torrys. This is the code:
{***************************
** 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: string; var 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;
 
 

Re:Detecting MSXM4Ldll version

MSXML4.DLL does not export the function "DllGetVersion" like "Shell32.dll"
or "comctl32.dll".
This Line
@DllGetVersion := GetProcAddress(hInstDll, 'DllGetVersion');
tries to access the function 'DllGetVersion'' in your DLL. If this function
does not exist, the return value is NULL.
The only way to get the information about a dll (or exe) is to use the
Version Information Functions to get the informations saved in the
VERSIONINFO ressource:
GetFileVersionInfo
GetFileVersionInfoSize
VerFindFile
VerInstallFile
VerLanguageName
VerQueryValue
To check what functions a DLL exports, you can create a list with, I guess
the implib tool. Or you use
DEPENDS.EXE from the Microsoft Plattform SDK to find our what functions the
DLL exports.
The only way is to access the VERSIONINFO ressource of your DLL and find the
information you need. you will find tons of code samples how to get this
information in the internet.... I guess Torry has at least one component
what makes this stuff. Maybe an example is shipped with your Delphi version?
In C++ Builder 6 there is an componet example that gets these VERSIONINFO
data...
Hope it helped a little
Thomas
"Matti Räih? <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
From torrys I found code that seems to be suitable for detecting dll:s
version information. However it dont work if I try to detect MSXML library
version. Can anyone advise me why and if someone has a solution please
inform me.

Thanks to Torrys. This is the code:

{***************************
** 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: string; var 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;