Article ID: 152254 - Last Review: November 21, 2006 - Revision: 4.1 BUG: You receive an error LNK2001 when you try to use the >> operator to serialize one of the extension DLL classes in Visual C++This article was previously published under Q152254 On This PageSYMPTOMS When attempting to build an application that uses classes
from an MFC extension DLL, the linker reports an error of the form:
mainfrm.obj : error LNK2001: unresolved external symbol
"class CArchive & __stdcall operator>>
(class CArchive &,class CClassInExtDLL * &)"
(??5@YGAAVCArchive@@AAV0@AAPAVCDummyDoc@@@Z)
CAUSE If an exported class is declared in an extension DLL and is
made serializable by the use of the macros DECLARE_SERIAL and IMPLEMENT_SERIAL,
the global function: RESOLUTION Create a new macro based on the DECLARE_SERIAL macro: In this resolution, the AFX_EXT_API prefix resolves the LNK2001 error by explicitly exporting the function operator>> when building the extension DLL. STATUS Microsoft has confirmed this to be a bug in the Microsoft
products listed at the beginning of this article. MORE INFORMATION In order to make a class serializable by the use of a
CArchive object, the class must be derived from CObject and must implement the
DECLARE_SERIAL and IMPLEMENT_SERIAL macros. These macros are needed because
they define an overloaded function, operator>>, explicitly for that
class. In a case where that class is defined in an extension DLL and is
exported by using the AFX_EXT_CLASS macro, the overloaded function,
operator>>, does not get exported along with the class. Thus, if the main
application instantiates an object of that class type and tries to serialize
that object by the use of a CArchive object, a LNK2001 unresolved external
error will occur. Sample CodeDeclare your class in the extension DLL this way:In the header (.h) file for CMyObject: REFERENCES For additional information on serialization and how to
export classes from extension DLL's, please see:
131946
(http://support.microsoft.com/kb/131946/
)
Bad pointer from RUNTIME_CLASS with class from _AFXDLL
APPLIES TO
| Article Translations
|
Back to the top
