Posts

Showing posts with the label CString

MFC: CString and error LNK2019

Spanish version / Versión en Español 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.

MFC: CString y el error LNK2019

Versión en inglés / English version Este error se manifiesta como "unresolved external symbol", lo cual nos puede llevar a pensar que nos falta definir una función, o que no linkeamos correctamente. Lo que ocurría en mi caso era que estaba usando la clase CString, que es un template, cosa que no sabía. Aún más: su definición depende de si se usa ATL o no, o si el proyecto está configurado para usar caracteres Unicode o ANSI. En mi caso particular, estaba llamando a un método de otra dll, configurada con ANSI, desde una configurada con Unicode. Por ende, las definiciones de CString no coincidían, para el compilador eran dos tipos diferentes. Por lo tanto, la solución fue ir a mi proyecto desde el Solution Explorer del Visual Studio, click derecho->Properties->General->Project Defaults->Character Set, y en ese combo box, setear Unicode.