Solved

Adding MFC to regular DLL

Posted on 1998-07-26
14
441 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 218
string initialization in java 11 122
bigDiff challenge 17 143
FizzBuzz challenge 9 87
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 …
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.

739 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