开发者

Error LNK2019 when using GetFileVersionInfoSize()

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 OnInit开发者_C百科Dialog();

};

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.


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.

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. Just add that to the library list in the linker properties.


The functions GetFileVersionInfo and GetFileVersionInfoSize are defined in Version.dll and Version.lib so make sure, you are liking to the appropriate libraries.


For VS2012 or 2013 add to Project Properties->Linker->Input->Additional Dependencies -> Add Version.lib


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜