Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Exporting Dialogbox in dll for use in another exe

Posted on 2000-05-17
Medium Priority
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
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
  • 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.
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

LVL 10

Accepted Solution

RONSLOW earned 600 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


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

688 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