The information in this article applies to:
SYMPTOMSWhen attempting to build an application that uses classes from an MFC extension DLL, the linker reports an error of the form: Specifically, this problem occurs for code that attempts to use the >> operator to serialize one of the extension DLL classes that use the DECLARE_SERIAL macro. CAUSEIf 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:
is not automatically exported along with the class. Therefore, if an
application tries to serialize an object of that class type by the use of
the >> operator, a LNK2001 unresolved external error occurs on operator >>.
RESOLUTIONCreate a new macro based on the DECLARE_SERIAL macro:
After defining this macro, use this new DECLARE_SERIAL_EXTDLL macro in
place of DECLARE_SERIAL in the class declaration. Rebuild the DLL and link
its new import library with the application.
In this resolution, the AFX_EXT_API prefix resolves the LNK2001 error by explicitly exporting the function operator>> when building the extension DLL. STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. MORE INFORMATIONIn 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:
Q131946 PRB: Bad Pointer from RUNTIME_CLASS with Class from _AFXDLL Additional query words: kbvc400bug kbvc410bug kbvc420bug kbvc500bug kbvc600bug
Keywords : kbprg kbDLL kbMFC kbVC kbVC500bug kbVC600bug |
Last Reviewed: July 29, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |