?
Solved

Linker Problem with Exporting CDialog  class

Posted on 1997-05-14
5
Medium Priority
?
390 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
  • 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

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

862 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