Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linker Problem with Exporting CDialog  class

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

609 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