Exporting Dialogbox in dll for use in another exe

Posted on 2000-05-17
Last Modified: 2013-11-20
I want to create a dll that will contain a dialog box class and export it for use in another application.  I thought I would start simple and build on it.  So I created a MFC AppWizard(dll) and setup a plain looking dialog box.  I then added a "AFX_EXT_CLASS" to the app class that was created by the wizard like so:

AFX_EXT_CLASS class  CHTTPpostApp : public CWinApp

this gives compile warnings:
warning C4091: '__declspec(dllimport ) ' : ignored on left of 'class CHTTPpostApp' when no variable is declared

so I tried:

class AFX_EXT_CLASS CHTTPpostApp : public CWinApp
which gave all kinds of warnings and error msgs

Can someone tell me how to export a dialog box and its functionality to an exe?  Maybe show me the changes that you need to make to an appwizard generated dll so that I have a simple starting point.
Question by:big_b
  • 6
  • 5
LVL 10

Expert Comment

ID: 2819511
don't change the definieiotn for the CWinApp derived class in the DLL.

You put the AFX_EXT_CLASS after the
word class in the class definition for the dialog itself.

It works liek a charm.

Author Comment

ID: 2821229
I did try your suggestion but was unable to get it to work I change the following line in my header file from:

class CMyHTTPDialog : public CDialog


class AFX_EXT_CLASS CMyHTTPDialog : public CDialog

And got the following compile errors:

E:\temp\HTTPpost\MyHTTPDialog.cpp(19) : warning C4273: 'CMyHTTPDialog::CMyHTTPDialog' : inconsistent dll linkage.  dllexport assumed.
E:\temp\HTTPpost\MyHTTPDialog.cpp(28) : warning C4273: 'DoDataExchange' : inconsistent dll linkage.  dllexport assumed.
E:\temp\HTTPpost\MyHTTPDialog.cpp(35) : warning C4273: '_GetBaseMessageMap' : inconsistent dll linkage.  dllexport assumed.
E:\temp\HTTPpost\MyHTTPDialog.cpp(35) : warning C4273: 'GetMessageMap' : inconsistent dll linkage.  dllexport assumed.
E:\temp\HTTPpost\MyHTTPDialog.cpp(35) : warning C4273: 'protected: static struct AFX_MSGMAP const  CMyHTTPDialog::messageMap' : inconsistent dll linkage.  dllexport assumed.
E:\temp\HTTPpost\MyHTTPDialog.cpp(35) : error C2491: 'CMyHTTPDialog::messageMap' : definition of dllimport static data member not allowed
E:\temp\HTTPpost\MyHTTPDialog.cpp(35) : warning C4273: 'private: static struct AFX_MSGMAP_ENTRY const * const  CMyHTTPDialog::_messageEntries' : inconsistent dll linkage.  dllexport assumed.
E:\temp\HTTPpost\MyHTTPDialog.cpp(35) : error C2491: 'CMyHTTPDialog::_messageEntries' : definition of dllimport static data member not allowed

There is nothing special about this dialog box that I know of.  It was created using the MFC AppWizard (DLL) and I thru a progress bar on it just so I could tell it was the one I created for the experiment.

Did I not understand your directions?

LVL 10

Expert Comment

ID: 2823909
I don't understand what's gone wrong.
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

LVL 10

Accepted Solution

RONSLOW earned 150 total points
ID: 2823958
I created an MFC AppWizard (dll)
Selected MFC Extension DLL (using shared MFC DLL)
I created a dialog resource and corresponding class
I added AFX_EXT_CLASS to my class header
All worked fine.

Just ensure that you have _AFXEXT defined in your C++

Author Comment

ID: 2825854
I must have accidently picked Regular DLL instead of MFC extension DLL.  When I re-did the wizard and made sure I picked Extension DLL everything worked fine!  As an aside, what is the best way to deal with resources used by the dll?  I just manually added the IDD_DIALOG1 to the resource.h file of testexe program.  I am kind of new to this (as if you could not tell) is there anything to watch out for?

LVL 10

Expert Comment

ID: 2825885
resources stay in the DLL, the main app will search in its own resources first, then in the DLL .. that is one of the benefits of extension DLLs.

Author Comment

ID: 2826149
I must still be doing something wrong... IDD_DIALOG1 appears in my MainDialog.h file (the main header for my dll)like so:

class AFX_EXT_CLASS MainDialog : public CDialog
// Construction
   MainDialog(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
   enum { IDD = IDD_DIALOG1 };
   // NOTE: the ClassWizard will add data members here

When I add the header to my exe project so that I can use MainDialog class it does not know what a IDD_DIALOG1 is (since it was defined in my resource.h in the dll project).  In order to get it to compile I had to add the line from my resource.h (dll project) to the resource.h in the exe project.  Like so:

#define IDD_DIALOG1  1002

Is this what you are supposed to do?  Should the IDD_DIALOG1 not been defined in the resource.h to begin with?

By the way I am going to add another 50 points to this just because you have had to revisit this several times!


LVL 10

Expert Comment

ID: 2826167
thanks for the points.

If you use the standard MFC way of putting the resource id in the .h file, then you need to add your DLL's resource id symbols to your main applications (you can do this by specifying for your main apps resource that it is to include the dll's resource.h as well).

the alternative is to get rid of the IDD = enum from your .h and put the IDD_DIALOG1 directly in the .cpp file instead. Now your main app won't see the id name for your resource, but all will stil work ok.

Author Comment

ID: 2826208
Of the two options you mention I may go with the second but I am not sure that I understand the first option you give.

Do you mean that in my exe's resource.h that I should have a line that looks like this:

#include "some path to where the dll project is\resource.h"

If it was you which way would you do it?


Author Comment

ID: 2826245
Adjusted points from 100 to 150
LVL 10

Expert Comment

ID: 2831518
You can do it from VS itself by right-clicking in the Resources Vier tree view and select "Resource Includes".  Add you dll's resrouce.h file to the list.

However, putting the ID number in the .CPP instead of the .H is better design anyeay .. it reduces dependancies.  Don't know why AppWizard writes the code that way in the first place.


Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 92
Looking for a specific application/software 2 110
withoutTen challenge 14 123
Problem to open Excel file 15 136
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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