Dave's Brain

Browse - Programming Tips - How can I get the version of COMCTL32.DLL or other Windows DLL?

Date: 2010feb4
OS: Windows
Language: C/C++

Q.  How can I get the version of COMCTL32.DLL or other Windows DLL?

A.  Many Windows DLLs export a function called DllGetVersion.
You can call this function to find the DLL's version.  If the function
doesn't not exist you can assume the DLL is pre-Windows 2000.
Here's some code to do it:

typedef struct _DllVersionInfo {
	DWORD cbSize;
	DWORD dwMajorVersion;
	DWORD dwMinorVersion;
	DWORD dwBuildNumber;
	DWORD dwPlatformID;


BOOL GetWindowsDllVersion(LPCSTR szDll, float &version)
	HMODULE			hModule;
	fDllGetVersion		pDllGetVersion;
	char			buf[100];

	version = 0.0;
	if ((hModule = LoadLibrary(szDll)) == NULL) return FALSE; 
	if ((pDllGetVersion = (fDllGetVersion) GetProcAddress(hModule, "DllGetVersion")) == NULL) return FALSE;
	ZeroMemory(&info, sizeof(info));
	info.cbSize = sizeof(info);
	if (pDllGetVersion(&info) != S_OK) return FALSE; 
	_snprintf(buf, sizeof(buf), "%d.%d", info.dwMajorVersion, info.dwMinorVersion);
	sscanf(buf, "%f", &version);
	return TRUE;

void ExampleUse()
	float		version;

	if (!GetWindowsDllVersion("COMCTL32.DLL", version))
		version = 4.0;

	if (version >= 4.7)
		// OK to use that feature in version 4.7 of the Common Controls

Add a comment

Sign in to add a comment
Copyright © 2008-2016, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.