
This section describes the function used to provide version information in a DLL.
The following programming elements are used to provide or obtain a DLL's version information:
| DllGetVersion |
| DLLGETVERSIONPROC |
| DLLVERSIONINFO |
HRESULT CALLBACK DllGetVersion(
DLLVERSIONINFO *pdvi
);
Implemented by many of the Windows shell DLLs to provide a method for obtaining DLL-specific version information. This function is not an API, but it is exported by name from the DLL.
To call this function, use the LoadLibrary and GetProcAddress functions to obtain the function pointer. The DLLGETVERSIONPROC type is used as the data type for the function pointer. For more information, see the comments at the end of this reference.
Because different DLLs implement this function, it is necessary to call LoadLibrary to obtain the instance handle to the DLL and then call GetProcAddress to obtain the function pointer. The following example shows a function that will attempt to use DllGetVersion for the supplied DLL and display the version information in a message box:
void GetDllVersion(LPCTSTR lpszDllName)
{
HINSTANCE hinstDll;
TCHAR szText[MAX_PATH] = TEXT("Could not load DLL");
//Load the DLL.
hinstDll = LoadLibrary(lpszDllName);
if(hinstDll)
{
DLLGETVERSIONPROC pDllGetVersion;
/*
You must get this function explicitly because the DLL might not implement
the function. Depending upon the DLL, the lack of implementation of the
function may be a version marker in itself.
*/
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress( hinstDll,
TEXT("DllGetVersion"));
if(pDllGetVersion)
{
DLLVERSIONINFO dvi;
HRESULT hr;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if(SUCCEEDED(hr))
{
wsprintf( szText,
TEXT("DLL Version = %d.%02d\nBuild# = %d\n"),
dvi.dwMajorVersion,
dvi.dwMinorVersion,
dvi.dwBuildNumber);
switch(dvi.dwPlatformID)
{
case DLLVER_PLATFORM_WINDOWS:
lstrcat(szText, TEXT("Platform is Windows"));
break;
case DLLVER_PLATFORM_NT:
lstrcat(szText, TEXT("Platform is Windows NT"));
break;
default:
lstrcat(szText, TEXT("Platform is not defined"));
break;
}
}
else
{
lstrcpy( szText,
TEXT("DllGetVersion Failed - Cannot determine DLL version."));
}
}
else
{
//If GetProcAddress failed, the DLL does not implement DllGetVersion.
lstrcpy( szText,
TEXT("GetProcAddress Failed - The DLL does not implement DllGetVersion."));
}
FreeLibrary(hinstDll);
}
else
{
lstrcpy(szText, TEXT("Could not load the DLL"));
}
MessageBox(NULL, szText, lpszDllName, MB_OK | MB_ICONINFORMATION);
}
Currently, most of the Windows shell DLLs implement DllGetVersion. These include, but are not limited to, Shell32.dll, Comctl32.dll, Shdocvw.dll, and Shlwapi.dll.
typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *);
This type definition is used to define a pointer to a DllGetVersion function. This pointer is used when calling the function dynamically by loading the library and getting the function's address. For more information, see the example in DllGetVersion.
typedef struct _DllVersionInfo
{
DWORD cbSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformID;
}DLLVERSIONINFO;
Receives DLL-specific version information. It is used with the DllGetVersion function.
| DLLVER_PLATFORM_WINDOWS | The DLL was built for all Windows platforms. |
| DLLVER_PLATFORM_NT | The DLL was built specifically for Windows NT. |
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.