Converting MFC MDI App to DLL (Experts, please) 
Author Message
 Converting MFC MDI App to DLL (Experts, please)

Has anyone successfully converted an MFC MDI application to a DLL? So
far, here's what I've done:

- Created new MFC DLL project
- Copied MFC MDI app source code to this project
- Changed _AFXDLL to _USRDLL in preprocessor definitions
- Removed Enable3dControls() from InitInstance()
- Compiled DLL

This apparently works for many people. But I keep getting a breakpoint
exception, which asserts somewhere in WINCORE.CPP, saying that I've
passed classes between threads. But that's not true.

My calling EXE creates a new thread, which loads the DLL dynamically.
As soon as the library is loaded, the CWinApp is instantiated. (Being
that it's declared globally) So InitInstance() gets called right away
and my MainFrame should pop-up right away?

But it never showed up until I appended SW_SHOW to the m_nCmdShow
inside ShowWindow() found in InitInstance(). After I did this the
MainFrame *finally* poped up for 2 seconds and that's when I started
getting breakpoint exceptions.

Has anyone had better success? Can anyone refer me to something on the
Internet that explains how to do this properly. I'm searching for such
information.

Thanks for your help,

Mario



Fri, 01 Oct 2004 10:42:26 GMT  
 Converting MFC MDI App to DLL (Experts, please)
I was able to figure the problem out. For those people wanting to
convert an MFC application to DLL, I am posting this article as my
contribution to the newsgroups.

To convert an MFC MDI app to DLL, these steps worked for me:

1. Create an empty DLL project with AppWizard
2. Copy your original MFC application over to this project
3. Remove Enable3dControls() from InitInstance()
4. Mask SW_SHOW to the m_nCmdShow in the ShowWindow() member function
of m_pFrameWnd
5. Create a member variable called m_bReady in your customized CWinApp
6. In constructor, initialize m_bReady to FALSE
7. Add the following to the very beginning of your InitInstance()

  if (!m_bReady) return TRUE;

8. Create an exported function in your DLL to syncrhonize resources
and show the main frame when you want it to:

void StartFrame()
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState());

  theApp.m_bReady = TRUE;
  theApp.InitInstance();
  theApp.Run();

Quote:
}

9. Finally, in your calling EXE create a thread using this function:

  typedef void (*PROC_START) (void);

  HMODULE hDLL = LoadLibrary("myappdll");
  PROC_START procStart =
(PROC_START)GetProcAddress(hDLL,"StartFrame");
  procStart();
  FreeLibrary(hDLL);

10. WARNING: some people say to make _AFXDLL to _USRDLL, but I keep
using _AFXDLL because it already defines _USRDLL and I am sharing the
MFC DLL which requires this definition.

I hope I'm able to save someone else very much time with this.

Mario Mueller


Quote:
> Has anyone successfully converted an MFC MDI application to a DLL? So
> far, here's what I've done:

> - Created new MFC DLL project
> - Copied MFC MDI app source code to this project
> - Changed _AFXDLL to _USRDLL in preprocessor definitions
> - Removed Enable3dControls() from InitInstance()
> - Compiled DLL

> This apparently works for many people. But I keep getting a breakpoint
> exception, which asserts somewhere in WINCORE.CPP, saying that I've
> passed classes between threads. But that's not true.

> My calling EXE creates a new thread, which loads the DLL dynamically.
> As soon as the library is loaded, the CWinApp is instantiated. (Being
> that it's declared globally) So InitInstance() gets called right away
> and my MainFrame should pop-up right away?

> But it never showed up until I appended SW_SHOW to the m_nCmdShow
> inside ShowWindow() found in InitInstance(). After I did this the
> MainFrame *finally* poped up for 2 seconds and that's when I started
> getting breakpoint exceptions.

> Has anyone had better success? Can anyone refer me to something on the
> Internet that explains how to do this properly. I'm searching for such
> information.

> Thanks for your help,

> Mario



Sun, 03 Oct 2004 14:43:39 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Trying to convert MFC App to MFC DLL

2. Convert existing mfc app from MDI to SDI

3. Convert MFC app to a DLL.

4. Converting MFC app to use MFC250 dll

5. Need help converting a console app to windows app with a DLL

6. Converting an App from SDI to MDI?

7. converting MDI app to ActiveX control

8. How to convert use shared MFC DLL to use MFC in static lib

9. Converting win32 dll to MFC dll

10. How to convert a regular DLL to an MFC DLL

11. Converting a MFC EXE into a MFC DLL

12. Converting MFC Extension dll into Regular dll statically linked

 

 
Powered by phpBB® Forum Software