简体   繁体   English

使用 GetFileVersionInfoSize() 时出现错误 LNK2019

[英]Error LNK2019 when using GetFileVersionInfoSize()

I just included this bit in my already working code, but I am getting an LNK2019 error.我刚刚将这一位包含在我已经工作的代码中,但我收到了 LNK2019 错误。 I'll paste the error after pasting the code.粘贴代码后我会粘贴错误。

The Class CAboutDlg has: Class CAboutDlg 具有:

public:

    CStatic m_VersionInfoCtrl;

   virtual BOOL OnInitDialog();

};

The Function itself: Function 本身:

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.谢谢。

You need to link against the library that contains the two functions VerQueryValue and GetFileVersionInfo - the linker doesn't know by default where to find them.您需要链接到包含两个函数VerQueryValueGetFileVersionInfo的库 - linker 默认情况下不知道在哪里可以找到它们。

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 is version.lib .在 MSDN 上快速搜索这两个函数表明它们都在系统库version.dll中,而您要链接的库是version.lib Just add that to the library list in the linker properties.只需将其添加到 linker 属性的库列表中即可。

The functions GetFileVersionInfo and GetFileVersionInfoSize are defined in Version.dll and Version.lib so make sure, you are liking to the appropriate libraries.函数GetFileVersionInfoGetFileVersionInfoSizeVersion.dllVersion.lib中定义,因此请确保您喜欢适当的库。

For VS2012 or 2013 add to Project Properties->Linker->Input->Additional Dependencies -> Add Version.lib对于 VS2012 或 2013 添加到 Project Properties->Linker->Input->Additional Dependencies -> Add Version.lib

I am also getting same error, while upgrading the VS6.0 application to VS2012 platform.在将 VS6.0 应用程序升级到 VS2012 平台时,我也遇到了同样的错误。

a.一个。 error LNK2019: unresolved external symbol _GetFileVersionInfoSizeA@8 referenced in function _main错误 LNK2019:未解析的外部符号 _GetFileVersionInfoSizeA@8 在 function _main 中引用

b.湾。 error LNK2019: unresolved external symbol _GetFileVersionInfoA@16 referenced in function _main错误 LNK2019:未解析的外部符号 _GetFileVersionInfoA@16 在 function _main 中引用

c. c。 error LNK2019: unresolved external symbol _VerQueryValueA@16 referenced in function _main错误 LNK2019:未解析的外部符号 _VerQueryValueA@16 在 function _main 中引用

Resolution:解析度:

I found that it is due to missing reference to library "Version.lib".我发现这是由于缺少对库“Version.lib”的引用。

a.一个。 For VS6.0 add it to Project Setting->Link->library modules对于 VS6.0,将其添加到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,添加到Project Properties->Linker->Input->Additional Dependancies并将完整的 lib 路径添加到 Include 目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM