Created
May 27, 2015 18:37
-
-
Save weltling/bc99faed4f09d615b7a7 to your computer and use it in GitHub Desktop.
Getting version from a windows dll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <iostream> | |
using std::cout; | |
void reportError() | |
{ | |
LPVOID lpMsgBuf; | |
FormatMessage( | |
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, | |
NULL, | |
GetLastError(), | |
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language | |
(LPTSTR) &lpMsgBuf, | |
0, | |
NULL ); | |
cout << (char*)lpMsgBuf << "\n"; | |
// Free the buffer. | |
LocalFree( lpMsgBuf ); | |
} | |
void main( int argc, char *argv[ ], char *envp[ ] ) | |
{ | |
cout << "\n"; | |
if(2 != argc) | |
{ | |
cout << "Syntax: GetVer <File Name>\n"; | |
return; | |
} | |
DWORD dwArg; | |
DWORD dwInfoSize = GetFileVersionInfoSize(argv[1], &dwArg); | |
if(0 == dwInfoSize) | |
{ | |
cout << "No version info available\n"; | |
reportError(); | |
return; | |
} | |
BYTE* lpBuff = new BYTE[dwInfoSize]; | |
if(!lpBuff) | |
{ | |
cout << "Out of Memory\n"; | |
return; | |
} | |
if(0 == GetFileVersionInfo(argv[1], 0, dwInfoSize, lpBuff)) | |
{ | |
cout << "Error retrieving version info\n"; | |
reportError(); | |
return; | |
} | |
VS_FIXEDFILEINFO *vInfo; | |
UINT uInfoSize; | |
if(0 == VerQueryValue(lpBuff, TEXT("\\"), | |
(LPVOID*)&vInfo, | |
&uInfoSize)) | |
{ | |
cout << "Version information not available\n"; | |
delete lpBuff; | |
return; | |
} | |
if(0 == uInfoSize) | |
{ | |
cout << "Version information not available\n"; | |
delete lpBuff; | |
return; | |
} | |
cout << argv[1] | |
<< " Version: " | |
<< HIWORD(vInfo->dwFileVersionMS) << "," | |
<< LOWORD(vInfo->dwFileVersionMS) << "," | |
<< HIWORD(vInfo->dwFileVersionLS) << "," | |
<< LOWORD(vInfo->dwFileVersionLS) << "\n"; | |
delete lpBuff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment