?
Solved

Linker Problem with Exporting CDialog  class

Posted on 1997-05-14
5
Medium Priority
?
383 Views
Last Modified: 2013-12-03
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)

0
Comment
Question by:suma051497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:lwiding
ID: 1397367
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
 

Author Comment

by:suma051497
ID: 1397368
Edited text of question
0
 
LVL 1

Expert Comment

by:lwiding
ID: 1397369
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
 

Author Comment

by:suma051497
ID: 1397370
Adjusted points to 200
0
 
LVL 1

Accepted Solution

by:
lwiding earned 400 total points
ID: 1397371
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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question