Solved

Linker Problem with Exporting CDialog  class

Posted on 1997-05-14
5
371 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 200 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MSDN Subscription - Azure and NFP's 3 59
VBA Error Since Excel 2016 x64 5 81
Problem to adjust sheet 1 81
Using MS Code on my Mac 6 45
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now