Solved

Exporting Dialogbox in dll for use in another exe

Posted on 2000-05-17
11
619 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
[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
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

622 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