使用 GetFileVersionInfoSize() 时出现错误 LNK2019
我刚刚将这一点包含在我已经工作的代码中,但我收到了 LNK2019 错误。粘贴代码后我将粘贴错误。
类 CAboutDlg 具有:
public:
CStatic m_VersionInfoCtrl;
virtual BOOL OnInitDialog();
};
函数本身:
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString inFileName = AfxGetApp()->m_pszExeName;
inFileName += ".exe";
void * theVersionInfo;
void * theFixedInfo;
unsigned long aVersionInfoSize = GetFileVersionInfoSize ( inFileName , &aVersionInfoSize);
CString returnString;
if (aVersionInfoSize)
{
theVersionInfo = new char [aVersionInfoSize];
GetFileVersionInfo ( inFileName, 0 , aVersionInfoSize, theVersionInfo) ;
unsigned int aSize = 0;
VerQueryValue( theVersionInfo , "\\" , &theFixedInfo , &aSize);
if (theFixedInfo)
{
VS_FIXEDFILEINFO * aInfo = (VS_FIXEDFILEINFO *) theFixedInfo;
DWORD dwMajorVersionMsb = HIWORD( aInfo->dwFileVersionMS );
DWORD dwMajorVersionLsb = LOWORD( aInfo->dwFileVersionMS );
DWORD dwMinorVersionMsb = HIWORD( aInfo->dwFileVersionLS );
DWORD dwMinorVersionLsb = LOWORD( aInfo->dwFileVersionLS );
returnString.Format("Version %d . %d . %d. %d",dwMajorVersionMsb,dwMajorVersionLsb,dwMinorVersionMsb,dwMinorVersionLsb);
//memcpy(sVer,returnString.GetBuffer(),returnString.GetLength()+1);
}
delete theVersionInfo;
}
m_VersionInfoCtrl.SetWindowText(returnString);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
....
它给了我以下三个错误:
1.RangemasterGenerator error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
2.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
3.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
... 我不明白问题是什么。任何人都可以帮忙吗? 谢谢。
I just included this bit in my already working code, but I am getting an LNK2019 error. I'll paste the error after pasting the code.
The Class CAboutDlg has:
public:
CStatic m_VersionInfoCtrl;
virtual BOOL OnInitDialog();
};
The Function itself:
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString inFileName = AfxGetApp()->m_pszExeName;
inFileName += ".exe";
void * theVersionInfo;
void * theFixedInfo;
unsigned long aVersionInfoSize = GetFileVersionInfoSize ( inFileName , &aVersionInfoSize);
CString returnString;
if (aVersionInfoSize)
{
theVersionInfo = new char [aVersionInfoSize];
GetFileVersionInfo ( inFileName, 0 , aVersionInfoSize, theVersionInfo) ;
unsigned int aSize = 0;
VerQueryValue( theVersionInfo , "\\" , &theFixedInfo , &aSize);
if (theFixedInfo)
{
VS_FIXEDFILEINFO * aInfo = (VS_FIXEDFILEINFO *) theFixedInfo;
DWORD dwMajorVersionMsb = HIWORD( aInfo->dwFileVersionMS );
DWORD dwMajorVersionLsb = LOWORD( aInfo->dwFileVersionMS );
DWORD dwMinorVersionMsb = HIWORD( aInfo->dwFileVersionLS );
DWORD dwMinorVersionLsb = LOWORD( aInfo->dwFileVersionLS );
returnString.Format("Version %d . %d . %d. %d",dwMajorVersionMsb,dwMajorVersionLsb,dwMinorVersionMsb,dwMinorVersionLsb);
//memcpy(sVer,returnString.GetBuffer(),returnString.GetLength()+1);
}
delete theVersionInfo;
}
m_VersionInfoCtrl.SetWindowText(returnString);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
....
Its giving me the following three errors:
1.RangemasterGenerator error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
2.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
3.RangemasterGenerator error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function "public: virtual int __thiscall CAboutDlg::OnInitDialog(void)" (?OnInitDialog@CAboutDlg@@UAEHXZ)
...
I am not able to understand what the problem is. Can anyone help please.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要链接包含两个函数
VerQueryValue
和GetFileVersionInfo
的库 - 默认情况下链接器不知道在哪里可以找到它们。在 MSDN 上快速搜索这两个函数表明它们都在系统库
version.dll
中,而您要链接的库是version.lib
。只需将其添加到链接器属性中的库列表中即可。You need to link against the library that contains the two functions
VerQueryValue
andGetFileVersionInfo
- the linker doesn't know by default where to find them.A quick search for the two functions on MSDN suggests that they're both in the system library
version.dll
and the library you want to link against isversion.lib
. Just add that to the library list in the linker properties.函数GetFileVersionInfo< /strong> 和 GetFileVersionInfoSize 定义于 < code>Version.dll 和
Version.lib
因此请确保您喜欢适当的库。The functions GetFileVersionInfo and GetFileVersionInfoSize are defined in
Version.dll
andVersion.lib
so make sure, you are liking to the appropriate libraries.在将 VS6.0 应用程序升级到 VS2012 平台时,我也遇到了同样的错误。
a. 错误 LNK2019:函数 _main 中引用的无法解析的外部符号 _GetFileVersionInfoSizeA@8
b. 错误LNK2019:函数_main中引用了无法解析的外部符号_GetFileVersionInfoA@16
c.错误LNK2019:函数_main中引用了无法解析的外部符号_VerQueryValueA@16
解决方案:
我发现这是由于缺少对库“Version.lib”的引用。
a. 对于 VS6.0,将其添加到项目设置->链接->库模块
b. 对于 VS2012,添加到项目属性->链接器->输入->其他依赖项
并将完整的 lib 路径添加到 Include 目录。
I am also getting same error, while upgrading the VS6.0 application to VS2012 platform.
a. error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function _main
b. error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function _main
c. error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function _main
Resolution:
I found that it is due to missing reference to library "Version.lib".
a. For VS6.0 add it to Project Setting->Link->library modules
b. For VS2012 add to Project Properties->Linker->Input->Additional Dependancies
and add full lib path to Include directory.
对于VS2012或2013添加到项目属性->链接器->输入->附加依赖项->添加版本.lib
For VS2012 or 2013 add to Project Properties->Linker->Input->Additional Dependencies -> Add Version.lib