MFC: CString and error LNK2019

This error is of the "unresolved external symbol" kind, which can lead us to believe that we misdeclared or forgot to define some function, or we are not linking correctly to some dll.

In my particular case, I was using the MFC CString class, which is actually a template class. I was not aware of that. Moreover, its definition changes according to some project options: ATL usage, Character Set, and there might be more.

More concretely, I was calling a function from another dll, which had Multi-Byte (ANSI) as its character set, and the calling dll was configured to use Unicode. Therefore, the CString definitions did not match and the error ensued.

So the solution consisted of going to the called dll's project Properties, General section, Project Defaults subsection, Character Set combo box, and setting it to Unicode.

Comments

Popular posts from this blog

VB.NET: Raise base class events from a derived class

Apache Kafka - I - High level architecture and concepts

Upgrading Lodash from 3.x to 4.x