Solved

Adding MFC to regular DLL

Posted on 1998-07-26
14
424 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 126
Turn a spreadsheet into a vba executable. 2 92
Fibonacci challenge 11 132
Sed question 2 100
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…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

792 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