Solved

Adding MFC to regular DLL

Posted on 1998-07-26
14
403 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 123
Separate files macro - Errors on larger data set 18 65
centeredAverage challenge 8 132
mapAB Challlenge 35 128
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…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

863 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

26 Experts available now in Live!

Get 1:1 Help Now