The Newbie The Newbie - 3 months ago 60
C++ Question

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

Answer

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.

Comments