Article ID: 152254
Article Last Modified on 11/21/2006
friend CArchive& AFXAPI operator>>(CArchive& ar, CMyObject* &pOb);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 >>.
#define DECLARE_SERIAL_EXTDLL(class_name) \
_DECLARE_DYNCREATE(class_name) \
AFX_EXT_API friend CArchive& AFXAPI \
operator>>(CArchive& ar, class_name* &pOb);
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.
#define DECLARE_SERIAL_EXTDLL(class_name) \
_DECLARE_DYNCREATE(class_name) \
AFX_EXT_API friend CArchive& AFXAPI \
operator>>(CArchive& ar, class_name* &pOb);
class AFX_EXT_CLASS CMyObject : public CObject
{
DECLARE_SERIAL_EXTDLL(CMyObject)
...
};
In the implementation (.cpp) file for CMyObject:
...
IMPLEMENT_SERIAL(CMyObject, CObject, YOUR_SCHEMA_NUMBER_HERE)
...
131946 Bad pointer from RUNTIME_CLASS with class from _AFXDLL
Additional query words: kbvc400bug kbvc410bug kbvc420bug kbvc500bug kbvc600bug
Keywords: kbtshoot kberrmsg kbbug kbdll kbprogramming KB152254