You may receive an LNK2019 error message when you build a Visual C++ 2005 or Visual C++ .NET application that uses a CString-derived class from a DLL file (309801)
The information in this article applies to:
- Microsoft Visual C++ 2005 Express Edition
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
This article was previously published under Q309801 Note Microsoft Visual C++ 2005, Microsoft Visual C++ .NET 2003, and Microsoft Visual C++ .NET 2002 support both the managed code
model that is provided by the Microsoft .NET Framework and the unmanaged native
Microsoft Windows code model. The information in this article applies only to
unmanaged Visual C++ code. SYMPTOMS When you build a Visual C++ 2005 or Visual C++ .NET application that uses a CString-derived class from a DLL file, you may receive an error message
that is similar to one of the following: Message 1 ClientProject error
LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall
ATL::CStringT<char,class StrTraitMFC<char,class
ATL::ChTraitsCRT<char>>>::CStringT<char,class
StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>(char const *)"
(__imp_??0?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@QAE@PBD@Z)
referenced in function _main Message 2 ClientProject error LNK2005: "public:
__thiscall ATL::CStringT<char,class StrTraitMFC<char,class
ATL::ChTraitsCRT<char>>>::~CStringT<char,class
StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>(void)"
(??1?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@QAE@XZ) already
defined in Simple.obj Message 3 ClientProject fatal error LNK1169: one or
more multiply defined symbols found CAUSE This behavior may occur if you use a class derived from CString that is also exported from a DLL. In Microsoft Visual Studio 2005 or in Microsoft Visual
Studio .NET, the CString class has changed to a template class, as demonstrated by the
following lines of code taken from afxstr.h:
typedef ATL::CStringT< wchar_t, StrTraitMFC< wchar_t > > CStringW;
typedef ATL::CStringT< char, StrTraitMFC< char > > CStringA;
typedef ATL::CStringT< TCHAR, StrTraitMFC< TCHAR > > CString;
Visual Studio automatically exports the appropriate template
instantiation for the CStringT template class that you derive from. However, when you import the
class, Visual Studio .NET sometimes does not correctly import that
instantiation. This results in the linker error messages listed in the
"Symptoms" section of this article. RESOLUTION To resolve this issue, explicitly import the template class
for CStringT and CSimpleStringT in the precompiled header (stdafx.h) file, as follows:
template class __declspec(dllimport) CStringT<TCHAR, StrTraitMFC<TCHAR, ChTraitsCRT<TCHAR> > >;
template class __declspec(dllimport) CSimpleStringT<TCHAR>;
Modification Type: | Major | Last Reviewed: | 1/9/2006 |
---|
Keywords: | kbDLL kberrmsg kbprb KB309801 kbAudDeveloper |
---|
|