Solved

Adding MFC to regular DLL

Posted on 1998-07-26
14
450 Views
Last Modified: 2013-11-20
I've written a regular DLL (without MFC) for use with some console apps.
Later, I realised that the DLL is also needed for some Windows apps.
I need to know the changes necessary on my existing DLL to add in
some MFC functions like displaying dialog boxes.

Here is how my existing DLL looks like

export.cpp
----------
#include "myclass.h"
#include <windows.h>

BOOL WINAPI DllEntryPoint(HINSTANCE hDLL, DWORD dwReason, LPVOID Reserved)
{
      switch(dwReason)
      {
      case DLL_PROCESS_ATTACH: break;
      case DLL_PROCESS_DETACH: break;
      }

      return TRUE;      
}

void first_export_function(void);
...

export.def
----------
LIBRARY MYDLL

CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD SINGLE

EXPORTS

first_export_function

-----------------------------------------

Just a simple case, first_export_function needs to display a dialog
box to show its I/O process status when called by an application.

Thanks in advance for any help rendered.
0
Comment
Question by:gangclar
[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
  • 8
  • 6
14 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1319763
Use MFC AppWizard (dll) to create the project and copy all the code for the exported functions. Look into the Advanced MFC Sample "DLLTRACE: Writes a DLL Statically Linked to the Framework Library" and add the following line of code to the beginning of every function exported from the DLL (see "Managing the State Data of MFC Modules" in Creating New Documents, Windows, and Views in the Visual C++ Programmer's Guide for discussion).

     AFX_MANAGE_STATE(AfxGetStaticModuleState());
0
 

Author Comment

by:gangclar
ID: 1319764
I did that before, and received an error message "Unexpected end of file" for at the export.cpp file.
0
 

Author Comment

by:gangclar
ID: 1319765
I did that before, and received an error message "Unexpected end of file" at the export.cpp file.
0
Percona Monitoring and Management and Grafana

Proactive monitoring is vital to a highly-available environment. We have a quick start guide on Experts Exchange for Grafana users.

 
LVL 23

Expert Comment

by:chensu
ID: 1319766
Check your source code carefully. There must be a syntax error. At the end of export.cpp, add a carriage return (a blank line). Is there a missing }?
0
 

Author Comment

by:gangclar
ID: 1319767
I've checked that nothing is wrong, i.e. no missing ";" or "}" mismatched.

Do you happen to know where can I get samples of DLL codes that uses MFC, preferably a simple MFC DLL for teaching purpose.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319768
I mentioned the Advanced MFC Sample "DLLTRACE: Writes a DLL Statically Linked to the Framework Library" which comes with Visual C++.
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1319769
The error "Unexpected end of file" might be caused by including incorrect header files.

Don't include <windows.h>.

Include either "stdafx.h" or <afxwin.h>.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319770
And include your own header files after the standard header files.
0
 

Author Comment

by:gangclar
ID: 1319771
I've looked at the referred sample, it's linking a DLL to the MFC framework. However, I'm attempting to use some MFC function within my codes that generate my existing DLL.

It looks complex to me, as I'm new to MFC.

Is there information/sample that show how to create MFC DLLs, especially the portion on exporting functions, e.g. how does the export definition file differs from the one I've quoted in the question ?

Thanks for the information
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319772
It seems that you want to create MFC extension DLLs. Look into the Advanced MFC Sample "DLLHUSK: Dynamically Links the MFC Library". And look into the documentation Visual C++ Programmer's Guide\Adding Program Functionality\Overviews\DLLs: Overview.
0
 

Author Comment

by:gangclar
ID: 1319773
I don't want MFC ext DLLs.

It is possible to show me an example of a MFC DLL that will beep and count the number of beeps since called ? The beep counter should be displayed as a dialog box on screen when the function is called.

Thanks again.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319774
Then the Advanced MFC Sample "DLLTRACE: Writes a DLL Statically Linked to the Framework Library" is similar to what you want. Just replace the code of the exported function with beeping and counting and displaying the dialog box.
0
 

Author Comment

by:gangclar
ID: 1319775
I've tried DLLTRACE, but reported missing TRACE.LIB in my release directory.

I read  " void FAR PASCAL EXPORT ProcessDllIdle(); " in the traceapi.h.

I wonder shouldn't this be appearing in a .DEF file ?

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319776
In Win32, FAR PASCAL EXPORT are defined as nothing.

You can also use __declspec(dllexport) to export the functions instead of using a DEF file.
0

Featured Post

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…

628 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