#define _WIN32_WINNT 0x0502 #include #include #include #include void WinErr(const char *Msg) { LPVOID lpMsgBuf; DWORD ErrorCode = GetLastError (); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, ErrorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); printf("%s: Windows error %ld: %s\n", Msg, ErrorCode, lpMsgBuf); LocalFree(lpMsgBuf); } #define LODWORD(l) ((DWORD)((DWORDLONG)(l))) char *fullpath (const char *path) { LPTSTR lpFilePart; DWORD nBufferLength = 0; LPTSTR lpBuffer = NULL; nBufferLength = GetFullPathName (path, 0, lpBuffer, &lpFilePart); if (!nBufferLength) return (char *) path; lpBuffer = (LPTSTR) malloc (nBufferLength + 1); if (!lpBuffer) return (char *) path; if (GetFullPathName (path, nBufferLength, lpBuffer, &lpFilePart)) return lpBuffer; else { free (lpBuffer); return (char *) path; } } char *searchpath (const char *path, const char *ext) { LPTSTR lpFilePart, lpExt = NULL; DWORD nBufferLength = 0; LPTSTR lpBuffer = NULL; if (!strchr (path, '.')) lpExt = (LPTSTR) ext; nBufferLength = SearchPath (NULL, path, lpExt, 0, lpBuffer, &lpFilePart); if (!nBufferLength) return (char *) path; lpBuffer = (LPTSTR) malloc (nBufferLength + 1); if (!lpBuffer) return (char *) path; if (SearchPath (NULL, path, lpExt, nBufferLength, lpBuffer, &lpFilePart)) return lpBuffer; else { free (lpBuffer); return (char *) path; } } int main (int argc, char **argv) { char *LibName; DLLVERSIONINFO2 DllVersionInfo; HRESULT hRes; HMODULE hDll; FARPROC pDllGetVersion; /* HRESULT DllGetVersion (DLLVERSIONINFO2 *pdvi) */ LibName = fullpath (argv[1]); /* try first the current directory */ hDll = LoadLibrary (LibName); if (!hDll) { free (LibName); LibName = searchpath(argv[1], ".dll"); hDll = LoadLibrary (LibName); } if (!hDll) { free (LibName); LibName = argv[1]; hDll = LoadLibrary (LibName); } printf ("Library: %s\n", LibName); if (!hDll) { free (LibName); WinErr ("LoadLibrary"); return -1; } pDllGetVersion = GetProcAddress (hDll, "DllGetVersion"); if (!pDllGetVersion) { WinErr ("Address DllGetVersion"); pDllGetVersion = GetProcAddress (hDll, "_DllGetVersion"); } if (!pDllGetVersion) { free (LibName); WinErr ("Address _DllGetVersion"); return -1; } ZeroMemory(&DllVersionInfo, sizeof(DllVersionInfo)); DllVersionInfo.info1.cbSize = sizeof (DllVersionInfo); hRes = pDllGetVersion ((DLLVERSIONINFO *) &DllVersionInfo); if (IS_ERROR (hRes)) { free (LibName); WinErr ("DllGetVersion"); printf ("DllGetVersion: error no: %ld\n", HRESULT_CODE (hRes)); return -1; } printf ("MajorVersion: %lu\n", DllVersionInfo.info1.dwMajorVersion); printf ("MinorVersion: %lu\n", DllVersionInfo.info1.dwMinorVersion); printf ("BuildNumber: %lu\n", DllVersionInfo.info1.dwBuildNumber); printf ("RevisionNumber (QFE): %u\n", LOWORD(LODWORD(DllVersionInfo.ullVersion))); printf ("ullVersion: %#I64X\n", DllVersionInfo.ullVersion); return 0; }