Linker Problem with Exporting CDialog class

I subclassed CDialog class to MyCDialog. I added the message map and all the good stuff. I am exporting MyCDialog from a DLL using AFX_EXT_CLASS. I then createded another VisC++ project and I layed out a Dialog using AppStudio and using Class Wizard I generated a Class TestDialog for this Dialog resource. I then manually changed the base class
of this ClassWiz generated class to be CMyDialog and then linked the previously built Library which has the exported MyCDialog . When I try to compile this class TestDialog I am getting Linker error saying that MessageMap is undefined. But if I comment out the MessageMap macros in TestDialog the linker has no problem. Another twist to this problem is that I am also exporting TestDialog from a DLL ( a different one from CMyDialog though ). I f the Message Map if I replace CMyDialog with CDialog then the linker error disappears.

Has anybody else faced this problem before....



THE FOLLOWING STUFF IS BEING EXPORTED FROM A DLL CALLED TDIALOG.DLL

#ifndef DLLExport
#define DllExport __declspec(dllexport)
#endif

class DllExport TDialogMFC : public CDialog
{
// Construction
public:
      TDialogMFC(UINT nIDTemplate,CCmdTarget* pParent);   // standard constructor
      virtual ~TDialogMFC();

// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(TDialogMFC)
      public:

      protected:
      //}}AFX_VIRTUAL

// Implementation
protected: // attributes
      

protected: // member functions

      // Generated message map functions
      //{{AFX_MSG(TDialogMFC)
      afx_msg void OnDestroy();
      afx_msg void OnKillFocus(CWnd* pNewWnd);
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()

};


THE FOLLOWING STUFF IS BEING EXPORTED FROM A DLL CALLED EXPORTDLG.DLL

#ifndef DLLExport
#define DllExport __declspec(dllexport)
#endif

class DllExport ExportDialog : public TDialogMFC
{
// Construction
public:
      ExportDialog(CCmdTarget* pParent = NULL);   // standard constructor

// Dialog Data
      //{{AFX_DATA(ExportDialog)
      //}}AFX_DATA


// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(ExportDialog)
      protected:
      //}}AFX_VIRTUAL

// Implementation
protected:

      // Generated message map functions
      //{{AFX_MSG(ExportDialog)
            // NOTE: the ClassWizard will add member functions here
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
};


I GET A LINKER ERROR WHEN I AM LINKING IN DEVELOPER STUDIO THE EXPORTDLG PROJECT
ExportDialog.obj : error LNK2001: unresolved external symbol "protected: static struct AFX_MSGMAP const  TDialogMFC::messageMap"(?messageMap@TDialogMFC@@1UAFX_MSGMAP@@B)

suma051497Asked:
Who is Participating?
 
lwidingConnect With a Mentor Commented:
Perhaps I was not clear enough, but it appears that you are having this problem because both classes are being declared as __declspec(dllexport) in the EXPORTDLG project. This is what caused the same error message to appear in the test that I did. To get around this, you need to make sure that the class definition for the TDialogMFC class is declared as __declspec(dllimport) in the EXPORTDLG project.
0
 
lwidingCommented:
In performing a VERY simple test, I was able to duplicate your problem, and solved it with the following code in the header defining the CMyDialogClass.

I got the problem you described when I did the ifdef based on _AFXDLL, which was also defined for my test app as well as for my test dll.

#ifdef _WINDLL
#define      DllExport      __declspec(dllexport)
#else
#define      DllExport      __declspec(dllimport)
#endif

class DllExport CMyDialog : public CDialog
{
};

If this is not clear enough, or does not quite apply, I will be happy to expand on this.
0
 
suma051497Author Commented:
Edited text of question
0
 
lwidingCommented:
From your added text, it does appear that what you are having happen is that in the files in EXPORTDLG.DLL, when you include the header definition for TDialogMFC, DllExport is defined as __declspec(dllexport), when it needs to be __declspec(dllimport).

What you may need to do is no rely on _AFXDLL or _WINDLL, but add your own defines which indicate when a DLL is being defined. For example, for TDIALOG.DLL, it would look like:

#ifndef TDialogDllExport
  #ifdef _TDIALOGDLL
    #define TDialogDllExport __declspec(dllexport)
  #else
    #define TDialogDllExport __declspec(dllimport)
  #endif
#endif

And create a similar set of defines for each DLL. You need to have the dllimport there in order for the links to be set up correctly by the compiler.
0
 
suma051497Author Commented:
Adjusted points to 200
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.