windows C++中如何获取DLL文件的版本信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/420185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the version information of a DLL file in C++
提问by Adam Oren
I need to get the version information of a DLL file I created in Visual Studio 2008 C++. How do I get it?
我需要获取我在 Visual Studio 2008 C++ 中创建的 DLL 文件的版本信息。我如何得到它?
回答by Adam Oren
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;
回答by Paul Dixon
If you want programmatic access, see Version Informationin MSDN for the APIs and data structures you need.
如果您想要以编程方式访问,请参阅MSDN 中的版本信息以了解您需要的 API 和数据结构。
回答by Henrik Hartz
Looks like you need to access the VS_VERSION_INFO resource; http://www.microsoft.com/msj/0498/c0498.aspx
看起来你需要访问 VS_VERSION_INFO 资源;http://www.microsoft.com/msj/0498/c0498.aspx
回答by frankodwyer
It should be there in the properties (version tab) when you open it in windows explorer
当您在 Windows 资源管理器中打开它时,它应该在属性(版本选项卡)中