Solved

Exporting Dialogbox in dll for use in another exe

Posted on 2000-05-17
11
610 Views
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.
0
Comment
Question by:big_b
  • 6
  • 5
11 Comments
 
LVL 10

Expert Comment

by:RONSLOW
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.
0
 

Author Comment

by:big_b
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

to:

class AFX_EXT_CLASS CMyHTTPDialog : public CDialog

And got the following compile errors:

Compiling...
MyHTTPDialog.cpp
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?


Brian
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2823909
I don't understand what's gone wrong.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 10

Accepted Solution

by:
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++
0
 

Author Comment

by:big_b
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?


Brian
0
 
LVL 10

Expert Comment

by:RONSLOW
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.
0
 

Author Comment

by:big_b
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
public:
   MainDialog(CWnd* pParent = NULL);   // standard constructor

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

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!

Brian

0
 
LVL 10

Expert Comment

by:RONSLOW
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.
0
 

Author Comment

by:big_b
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?

Brian
0
 

Author Comment

by:big_b
ID: 2826245
Adjusted points from 100 to 150
0
 
LVL 10

Expert Comment

by:RONSLOW
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.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 104
string initialization in java 11 115
mapBully challenge 6 156
how to use laptop or pad camera in vb.net windows application 2 86
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…
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 …
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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