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

耗尽温柔 提交于 2019-12-28 12:28:14

问题


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


回答1:


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;



回答2:


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




回答3:


Looks like you need to access the VS_VERSION_INFO resource; http://www.microsoft.com/msj/0498/c0498.aspx




回答4:


It should be there in the properties (version tab) when you open it in windows explorer



来源:https://stackoverflow.com/questions/420185/how-to-get-the-version-information-of-a-dll-file-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!