Skip to content

Instantly share code, notes, and snippets.

@weltling weltling/filever.cpp
Created May 27, 2015

Embed
What would you like to do?
Getting version from a windows dll
#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
You can’t perform that action at this time.