Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the version information of a DLL file in C++

I need to get the version information of a DLL file I created in Visual Studio 2008 C++. How do I get it?

like image 840
Adam Oren Avatar asked Jan 07 '09 12:01

Adam Oren


People also ask

How do I find the DLL version?

If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there. In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.

How do I find the version of a file?

You can use the FileVersionInfo. FileVersion property with the Get-Command to get the file version in PowerShell. The following command gets the file version number of a file C:\Windows\System32\ActionCenter. dll .

How do I programmatically get the version of a DLL or EXE file?

The easiest way is to use the GetFileVersionInfoEx or GetFileVersionInfo API functions.


2 Answers

Thanks for the answers.

This worked for me:

WCHAR fileName[_MAX_PATH];
DWORD size = GetModuleFileName(g_dllHandle, fileName, _MAX_PATH);
fileName[size] = NULL;
DWORD handle = 0;
size = GetFileVersionInfoSize(fileName, &handle);
BYTE* versionInfo = new BYTE[size];
if (!GetFileVersionInfo(fileName, handle, size, versionInfo))
{
    delete[] versionInfo;
    return;
}
// we have version information
UINT                len = 0;
VS_FIXEDFILEINFO*   vsfi = NULL;
VerQueryValue(versionInfo, L"\\", (void**)&vsfi, &len);
aVersion[0] = HIWORD(vsfi->dwFileVersionMS);
aVersion[1] = LOWORD(vsfi->dwFileVersionMS);
aVersion[2] = HIWORD(vsfi->dwFileVersionLS);
aVersion[3] = LOWORD(vsfi->dwFileVersionLS);
delete[] versionInfo;
like image 60
Adam Oren Avatar answered Sep 28 '22 11:09

Adam Oren


If you want programmatic access, see Version Information in MSDN for the APIs and data structures you need.

like image 26
Paul Dixon Avatar answered Sep 28 '22 09:09

Paul Dixon