Linking in MFC Extension DLL's

Environment Visual C++ 5.0, NT 4.0

I am having trouble getting two MFC extension DLL's to link together. I have an extension DLL that contains a view and various functions and classes for that view. If I link this to an MFC EXE, all is fine.

However I want to link this to another MFC extension DLL that is then linked into an EXE. When I do this it fails to link correctly, giving the error:

--------------------Configuration: test2 - Win32 Debug--------------------
   Creating library Debug/test2.lib and object Debug/test2.exp
DibView.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const  AZDIBVIEW::classAZDIBVIEW" (?classAZDIBVIEW@AZDIBVIEW@@2UCRuntimeClass@@B)
DibView.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const  AZDIBVIEW::messageMap" (?messageMap@AZDIBVIEW@@1UAFX_MSGMAP@@B)
Debug/test2.dll : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

test2.dll - 3 error(s), 0 warning(s)

Is there a reason that I can not link two MFC extension DLL's together? The following extract is from the header file, and cpp file for the first extension DLL. the second extension DLL just adds a new class based on a CView (as with the EXE that I tested in originally) and then I replace CView with AZDIBVIEW.

The header of the first extension DLL is:

class AFX_EXT_CLASS AZDIBVIEW : public CView

friend class AZDRAWANNOTOOL;
friend class AZDRAWANNO;
friend class AZRECTANNOTOOL;
friend class AZDRAWRECT;

AZDIBVIEW();           // protected constructor used by dynamic creation

// These functions can be called from anywhere that has a pointer to the
view. They
// are used to control the image and the annotations used by the view.
Annotations are
// added through the document, and can be removed as a whole by the
document. Individual
// annotaions are removed by selecting and then removing from the view.
BOOL ToggleAnnoTips();
BOOL ToggleAnnotations();
void DeleteSelectedAnnos();
static void UpdateDIBViews();
void SetUserTool( AZTOOL tool );
void SetUserMode( AZMODE mode );
int GetZoomPercent();

// These are the overidable functions that should be called from your view.
virtual void GetViewMenu( CMenu&entA menu ) { popupviewmenu = FALSE; }
virtual void GetAnnoMenu( CMenu&nutA menu ) { popupannomenu = FALSE; }
virtual CSize GetImageSize();

virtual CDrawObjList* GetObjects() = 0;//{ return NULL; }
virtual void Remove( AZDRAWANNO* pObj ) = 0;//{;}
virtual AZDIB* GetDIBImage() = 0;//{ return NULL; }
virtual void DrawAnnotations( CDC* pDC ) = 0;//{;}
virtual AZDRAWANNO* ObjectAt( const CPoint&onsn point, AZDIBVIEW* pView ) =
0;//{ return NULL; };
virtual void Add( AZDRAWANNO* pObj ) = 0;//{;}

// ClassWizard generated virtual function overrides
virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD
dwStyle, const RECT&Name rect, CWnd* pParentWnd, UINT nID, CCreateContext*
pContext = NULL);
virtual void OnInitialUpdate();     // first time after construct
virtual void OnDraw(CDC* pDC);
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView*

// Implementation
virtual ~AZDIBVIEW();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext&sEWV dc) const;

// Generated message map functions
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnUpdateZoomtool(CCmdUI* pCmdUI);
afx_msg void OnUpdateSelecttool(CCmdUI* pCmdUI);

// These functions and variables are for use within the class and by its
friend classes
// only. Don't tamper with them, you are likely to corrupt the image of the
DLL that is
// being used by your software, this will give serious bugs in your code.
virtual BOOL IsAnnotationsOn();

// functions for dealing with annotation tips
BOOL HoldUpAnno( CRect&nsOn position, CPoint point );
BOOL IsAnnoTipsOn();
void KillTimedTips();
void TimedTips( CPoint imagepoint, CPoint screenpoint );
void MoveTips(  CPoint imagepoint, CPoint screenpoint  );
void HideTips();
void DrawTips(  CPoint imagepoint, CPoint screenpoint  );

// functions for dealing with annotations and annotations list
AZDRAWANNO* GetLastAnnotation();
AZDRAWANNO* GetNextAnnotation( POSITION&ionA pos );
POSITION GetAnnotationHeadPos();
AZDRAWANNO* GetFirstAnnotation();
int SelectedAnnotations();
BOOL IsSelected( AZDRAWANNO* pObj );
BOOL CheckForObjectEdge( CRect rect );
void RemoveViewAnno( AZDRAWANNO* pObj );
void SelectWithinRect( CRect rect, BOOL bAdd );
void DeSelect( AZDRAWANNO* pObj );
void Select( AZDRAWANNO* pObj, BOOL bAdd = FALSE );
void InvalObj( AZDRAWANNO* pObj );

// functions for mapping between client and image space
void ClientToDoc( CPoint&Rect point );
void ClientToDoc( CRect&Rec rect );
void DocToClient( CPoint&Rect point, AZHANDLE pixel = CENTER );
void DocToClient( CRect&Rec rect, AZHANDLE pixel = CENTER );
BOOL ResetScrollBars( CPoint point );
void ClientToScrollValue( CPoint&llVa clientpoint );
void ScrollToClientValue( CPoint&ntVa clientpoint );
BOOL IsImageScrolled( UINT nBar );
SCROLLINFO GetScrollInfo( int nBar, UINT nMask = SIF_ALL );

// functions for dealing with zooming
void ZoomImage( CPoint point );
AZMODSIDE FindZoomSide( CRect zoomrect );

// functions for updating and drawing the client space
void ScrollDIB( UINT bar, UINT nSBCode, UINT nPos );
void UpdatePartialArea( CDC* pDC, CRect clientrect );
void UpdateClientArea( CDC* pDC, CRect clientrect, BOOL realimage =
BOOL IsActive();

// variables defined here

and then its corresponding cpp file includes the following lines. I have
removed any additional functions, as I guess they should not affect whether
the MSG_MAP can be resolved.



Thanks in advance,
Spencer Jones,
Azure Limited.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tommy HuiEngineerCommented:
When you link in an import library (which is what an extension DLL will produce as well as the .DLL), all that means to to the linker is, "if my target uses anything from this library, make a reference to it". But the important thing to remember is that the linker does not copy the import library into your target (otherwise, it defeats the purpose of DLLs). So your all-purpose extension DLL does not have a copy of the specialized extension DLL. And when you create your exe, you must specify all the import libraries it needs: In this case, both extension DLLs.
sdjAuthor Commented:
I'm not sure whether you misunderstood my question or I am missing the point of your answer? This works:

MFC EXTENSION (withview) -- MFC EXE (using view)

This does not:

MFC EXTENSION1 (with view) -- MFC EXTENSION2 (using view)

MFC EXTENSION2, includes the lib file for MFC EXTENSION1, as with the EXE example that *does* work. However MFC EXTENSION2 compiles but fails to link for the RUNTIME CLASS and MSG_MAP information. Everything else is linking fine. Why is the RUNTIME CLASS and MSG_MAP not being exported for MFC_EXTENSION2?
The problem is with  AFX_EXT_CLASS macro.
This macro is defined by MFC as __declspec(dllexport) when the preprocessor symbols _AFXDLL and _AFXEXT are defined.
When you including first DLL include file to second MFC extention it macro EXPORTING class , not importing :-)
Because _AFXDLL and _AFXEXT also defined in second DLL project.

Solution is :
In the end of stdafx.h add :
// "MY" word different for different MFC extentions :-)
In your include file add:

#ifndef MY_EXT_CLASS
class MY_EXT_CLASS CMyExportingClass

this declaration exporting class when you inside class` project and importing in all other projects

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.