Solved

Exporting Dialogbox in dll for use in another exe

Posted on 2000-05-17
11
598 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now